package com.ruoyi.project.modules.interfaceinfo.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.page.PageMethod;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysDictType;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.modules.businessSystem.domain.BusinessSystem;
import com.ruoyi.project.modules.businessSystem.service.IBusinessSystemService;
import com.ruoyi.project.modules.domainInfo.domain.DomainInfo;
import com.ruoyi.project.modules.domainInfo.domain.DomainObjectInfo;
import com.ruoyi.project.modules.domainInfo.service.IDomainInfoService;
import com.ruoyi.project.modules.errorCodeCategory.domain.ErrorCodeCategory;
import com.ruoyi.project.modules.errorCodeCategory.service.IErrorCodeCategoryService;
import com.ruoyi.project.modules.fieldEnum.domain.FieldEnum;
import com.ruoyi.project.modules.fieldEnum.service.IFieldEnumService;
import com.ruoyi.project.modules.fileInfo.domain.FileInf;
import com.ruoyi.project.modules.fileInfo.service.IFileInfoService;
import com.ruoyi.project.modules.frontInterfaceFieldSource.domain.FrontInterfaceFieldSource;
import com.ruoyi.project.modules.frontInterfaceFieldSource.service.IFrontInterfaceFieldSourceService;
import com.ruoyi.project.modules.interfaceObject.domain.InterfaceObject;
import com.ruoyi.project.modules.interfaceObject.service.IInterfaceObjectService;
import com.ruoyi.project.modules.interfaceinfo.domain.InterfaceInfo;
import com.ruoyi.project.modules.interfaceinfo.domain.VirtualUsage;
import com.ruoyi.project.modules.interfaceinfo.request.*;
import com.ruoyi.project.modules.interfaceinfo.service.IInterfaceInfoService;
import com.ruoyi.project.modules.interfaceinfo.service.IVirtualUsageService;
import com.ruoyi.project.modules.interfaceinfo.vo.InterfaceFieldVo;
import com.ruoyi.project.modules.interfaceinfo.vo.InterfaceParam;
import com.ruoyi.project.modules.interfaceinfo.vo.InterfaceParamVo;
import com.ruoyi.project.modules.interfaceinfo.vo.InterfaceUser;
import com.ruoyi.project.modules.page.domain.Page;
import com.ruoyi.project.modules.page.service.IPageService;
import com.ruoyi.project.modules.parameter.domain.InterfaceParamsFieldRelation;
import com.ruoyi.project.modules.parameter.domain.ParamsFieldRelation;
import com.ruoyi.project.modules.parameter.mapper.ParamsFieldRelationMapper;
import com.ruoyi.project.modules.parameter.service.IInterfaceParamsFieldRelationService;
import com.ruoyi.project.modules.parameter.service.IParamsFieldRelationService;
import com.ruoyi.project.modules.processBranch.domain.ProcessBranch;
import com.ruoyi.project.modules.processBranch.service.IProcessBranchService;
import com.ruoyi.project.modules.product.domain.ProductInfo;
import com.ruoyi.project.modules.product.service.IProductInfoService;
import com.ruoyi.project.modules.productVersionObejct.domain.ProductVersionObejct;
import com.ruoyi.project.modules.productVersionObejct.service.IProductVersionObejctService;
import com.ruoyi.project.modules.questionInfo.domain.QuestionInfo;
import com.ruoyi.project.modules.questionInfo.service.IQuestionInfoService;
import com.ruoyi.project.modules.table.domain.FieldInfo;
import com.ruoyi.project.modules.table.domain.FieldStatus;
import com.ruoyi.project.modules.table.domain.TableInfo;
import com.ruoyi.project.modules.table.service.IFieldStatusService;
import com.ruoyi.project.modules.table.service.ITableInfoService;
import com.ruoyi.project.modules.tableObject.domain.TableObject;
import com.ruoyi.project.modules.tableObject.service.ITableObjectService;
import com.ruoyi.project.modules.usage.domain.Usage;
import com.ruoyi.project.modules.usage.service.IUsageService;
import com.ruoyi.project.modules.userDataAuth.service.IUserDataAuthService;
import com.ruoyi.project.modules.virtualUsageFieldMerge.domain.VirtualUsageFieldMerge;
import com.ruoyi.project.modules.virtualUsageFieldMerge.service.IVirtualUsageFieldMergeService;
import com.ruoyi.project.modules.virtualUsageGroup.domain.VirtualUsageGroup;
import com.ruoyi.project.modules.virtualUsageGroup.service.IVirtualUsageGroupService;
import com.ruoyi.project.modules.virtualUsageGroupDetail.domain.VirtualUsageGroupDetail;
import com.ruoyi.project.modules.virtualUsageGroupDetail.service.IVirtualUsageGroupDetailService;
import com.ruoyi.project.modules.virtualUsageParamSource.domain.VirtualUsageParamSource;
import com.ruoyi.project.modules.virtualUsageParamSource.mapper.VirtualUsageParamSourceMapper;
import com.ruoyi.project.modules.virtualUsageParamSource.service.IVirtualUsageParamSourceService;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * TODO
 *
 * @author chenxiaoyu
 * @version 1.0
 * @date 2021/12/2 下午11:00
 */
@Controller
@RequestMapping("/interface/interface")
@AllArgsConstructor
public class InterfaceInfoNewController extends BaseController {

    private static final String prefix = "interface/interface/new";

    private IInterfaceInfoService interfaceInfoService;

    private IUserDataAuthService userDataAuthService;

    private IQuestionInfoService questionInfoService;

    private IPageService pageService;

    private IBusinessSystemService businessSystemService;

    private ITableObjectService tableObjectService;

    private IParamsFieldRelationService paramsFieldRelationService;

    private IInterfaceParamsFieldRelationService interfaceParamsFieldRelationService;

    private ITableInfoService tableInfoService;

    private IVirtualUsageService virtualUsageService;

    private IFieldStatusService fieldStatusService;

    private ISysDictDataService sysDictDataService;

    private ISysDictTypeService sysDictTypeService;

    private IInterfaceObjectService interfaceObjectService;

    private IUsageService usageService;

    private IProductVersionObejctService productVersionObejctService;

    private IProductInfoService productInfoService;

    private IDomainInfoService domainInfoService;

    private IVirtualUsageParamSourceService virtualUsageParamSourceService;

    private IVirtualUsageGroupService virtualUsageGroupService;

    private IVirtualUsageGroupDetailService virtualUsageGroupDetailService;

    private IFrontInterfaceFieldSourceService frontInterfaceFieldSourceService;

    private IVirtualUsageFieldMergeService virtualUsageFieldMergeService;

    private IProcessBranchService processBranchService;
    /**
     * 编辑接口页面
     * @return
     */
    @GetMapping("/editInterface/{id}")
    public String editInterface(@PathVariable("id") Long id, ModelMap mmap) {
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(id);
        mmap.put("interfaceInfo", interfaceInfo);

        DomainInfo domainInfo = new DomainInfo();
        List<DomainInfo> domainInfos = this.domainInfoService.selectDomainInfoList(domainInfo);
        mmap.put("domainInfoList", domainInfos);
        List<DomainObjectInfo> domainObjectInfos = new ArrayList<>();
        if (interfaceInfo.getDomainId() != null) {
            DomainInfo domainInfo1 = this.domainInfoService.selectDomainInfoById(interfaceInfo.getDomainId());
            if (domainInfo1 != null && domainInfo1.getDomainObjectInfoList() != null) {
                domainObjectInfos = domainInfo1.getDomainObjectInfoList();
            }
        } else {
            if (CollectionUtil.isNotEmpty(domainInfos)) {
                DomainInfo domainInfo1 = this.domainInfoService.selectDomainInfoById(domainInfos.get(0).getId());
                if (domainInfo1 != null && domainInfo1.getDomainObjectInfoList() != null) {
                    domainObjectInfos = domainInfo1.getDomainObjectInfoList();
                }
            }
        }
        mmap.put("domainObjectList", domainObjectInfos);
        String isUsed = "0";
        if (!"2".equals(interfaceInfo.getFbType())) {
            VirtualUsage virtualUsage = new VirtualUsage();
            virtualUsage.setInterfaceId(id);
            List<VirtualUsage> virtualUsages = this.virtualUsageService.selectVirtualUsageList(virtualUsage);
            if (CollectionUtil.isNotEmpty(virtualUsages)) {
                isUsed = "1";
            }
        }
        mmap.put("isUsed", isUsed);

        ProductVersionObejct productVersionObejct = new ProductVersionObejct();
        productVersionObejct.setObjectType("5");
        productVersionObejct.setObjectId(id);
        List<Long> productIds = new ArrayList<>();
        List<ProductVersionObejct> productVersionObejcts = this.productVersionObejctService.selectProductVersionObejctList(productVersionObejct);
        if(CollectionUtil.isNotEmpty(productVersionObejcts)) {
            productIds = productVersionObejcts.stream().map(ProductVersionObejct::getTableProductVersionId).collect(Collectors.toList());
        }
        mmap.put("productIds", productIds);
        ProductInfo productInfo = new ProductInfo();
        productInfo.setVersionType("1");
        List<ProductInfo> productList = this.productInfoService.selectProductInfoList(productInfo);
        mmap.put("productList", productList);

        if ("1".equals(interfaceInfo.getFbType())) {
            return prefix + "/method_edit";
        } else if ("3".equals(interfaceInfo.getFbType())) {
            return prefix + "/dubbo_edit";
        }
        InterfaceObject interfaceObject = new InterfaceObject();
        interfaceObject.setObjectType("2");
        interfaceObject.setInterfaceId(id);
        List<InterfaceObject> interfaceObjectList = this.interfaceObjectService.selectInterfaceObjectList(interfaceObject);
        List<Long> pageIds = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(interfaceObjectList)) {
            pageIds = interfaceObjectList.stream().map(InterfaceObject::getObjectId).collect(Collectors.toList());
        }
        mmap.put("pageIds", pageIds);
        Long usageId = 0l;
        interfaceObject.setObjectType("3");
        interfaceObjectList = this.interfaceObjectService.selectInterfaceObjectList(interfaceObject);
        if (CollectionUtil.isNotEmpty(interfaceObjectList)) {
            usageId = interfaceObjectList.get(0).getObjectId();
        }
        interfaceInfo.setUsageId(usageId);
        Page page = new Page();
        List<Page> pageList = this.pageService.selectPageList(page);
        Usage usage = new Usage();
        List<Usage> usageList = this.usageService.selectUsageList(usage);
        mmap.put("pageList", pageList);
        mmap.put("usageList", usageList);

        return prefix + "/bff_edit";
    }

    /**
     * 保存dubbo接口信息
     * @param dubboInterfaceAddReq
     * @return
     */
    @PostMapping("/editDubboNew")
    @ResponseBody
    public AjaxResult editDubboNew(@RequestBody DubboInterfaceAddReq dubboInterfaceAddReq) {
        interfaceInfoService.editDubboInterface(dubboInterfaceAddReq);
        return success();
    }

    /**
     * 更新接口排序
     * @param dubboInterfaceAddReq
     * @return
     */
    @PostMapping("/updateSort")
    @ResponseBody
    public AjaxResult updateSort(@RequestBody DubboInterfaceAddReq dubboInterfaceAddReq) {
        interfaceInfoService.updateSort(dubboInterfaceAddReq);
        return success();
    }

    /**
     * method 字段参数选择页面
     * @param interfaceId 接口id
     * @param isInParam 1 入参 2 出参
     * @param mmap mmap
     * @return
     */
    @GetMapping("method_field_choose/{interfaceId}/{isInParam}")
    public String method_field_choose(@PathVariable("interfaceId") Long interfaceId,
                                     @PathVariable("isInParam") Long isInParam,
                                     ModelMap mmap) {
        mmap.put("interfaceId", interfaceId);
        mmap.put("isInParam", isInParam);
        List<TableInfo> tableInfoList = this.interfaceParamsFieldRelationService.tableList(interfaceId, "1", isInParam);
        List<Long> fieldIdList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(tableInfoList)) {
            for (TableInfo tableInfo : tableInfoList) {
                for (FieldInfo fieldInfo : tableInfo.getFieldInfoList()) {
                    fieldIdList.add(fieldInfo.getId());
                }
            }
        } else {
            tableInfoList = new ArrayList<>();
        }
        mmap.put("tableInfoList", tableInfoList);
        mmap.put("fieldIdList", fieldIdList);
        return prefix + "/method_field_choose";
    }

//    /**
//     * dubbo接口 字段参数选择页面
//     * @param interfaceId 接口id
//     * @param isInParam 1 入参 2 出参
//     * @param mmap mmap
//     * @return
//     */
//    @GetMapping("dubbo_field_choose/{interfaceId}/{isInParam}")
//    public String dubbo_field_choose(@PathVariable("interfaceId") Long interfaceId,
//                                     @PathVariable("isInParam") Long isInParam,
//                                     ModelMap mmap) {
//        mmap.put("interfaceId", interfaceId);
//        mmap.put("isInParam", isInParam);
//        List<TableInfo> tableInfoList = this.interfaceParamsFieldRelationService.tableList(interfaceId, "1", isInParam);
//        List<Long> fieldIdList = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(tableInfoList)) {
//            for (TableInfo tableInfo : tableInfoList) {
//                for (FieldInfo fieldInfo : tableInfo.getFieldInfoList()) {
//                    fieldIdList.add(fieldInfo.getId());
//                }
//            }
//        } else {
//            tableInfoList = new ArrayList<>();
//        }
//        mmap.put("tableInfoList", tableInfoList);
//        mmap.put("fieldIdList", fieldIdList);
//        return prefix + "/dubbo_field_choose";
//    }

    @GetMapping("params_field_choose/{id}")
    public String params_field_choose(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("id", id);
        List<TableInfo> tableInfoList = paramsFieldRelationService.tableList(id);
        List<Long> fieldIdList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(tableInfoList)) {
            for (TableInfo tableInfo : tableInfoList) {
                for (FieldInfo fieldInfo : tableInfo.getFieldInfoList()) {
                    fieldIdList.add(fieldInfo.getId());
                }
            }
        } else {
            tableInfoList = new ArrayList<>();
        }
        mmap.put("tableInfoList", tableInfoList);
        mmap.put("fieldIdList", fieldIdList);
        return prefix + "/params_field_choose";
    }

    @PostMapping("/saveParamsField")
    @ResponseBody
    public AjaxResult saveParamsField(ParamsFieldRelation paramsFieldRelation) {
        paramsFieldRelationService.saveParamsField(paramsFieldRelation);
        return success();
    }

    @GetMapping("dubbo_table_model_choose")
    public String dubbo_table_model_choose(@RequestParam String tableIds, ModelMap mmap) {
        mmap.put("tableIds", tableIds);
        return prefix + "/dubbo_table_model_choose";
    }

    @GetMapping("method_table_model_choose")
    public String method_table_model_choose(@RequestParam String tableIds, ModelMap mmap) {
        mmap.put("tableIds", tableIds);
        return prefix + "/method_table_model_choose";
    }

    @GetMapping("data_map_choose/{isInParam}/{interfaceId}/{type}")
    public String data_map_choose(@PathVariable("isInParam") String isInParam,
                                  @PathVariable("interfaceId") Long interfaceId,
                                  @PathVariable("type") Long type,
                                     ModelMap mmap) {
        mmap.put("isInParam", isInParam);
        mmap.put("interfaceId", interfaceId);
        mmap.put("type", type);
        ListInterfaceFieldParamReq listInterfaceFieldParamReq = new ListInterfaceFieldParamReq();
        listInterfaceFieldParamReq.setType(type + "");
        listInterfaceFieldParamReq.setInterfaceId(interfaceId);
        listInterfaceFieldParamReq.setIsInParam(isInParam);
        List<InterfaceParam> listFieldParam = this.interfaceInfoService.listInterfaceParams(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(listFieldParam)) {
            List<Long> fieldIds = listFieldParam.stream().map(InterfaceParam::getFieldId).collect(Collectors.toList());
            mmap.put("fieldIds", fieldIds);
        } else {
            mmap.put("fieldIds", new ArrayList<Long>());
        }
        VirtualUsage virtualUsage = new VirtualUsage();
        virtualUsage.setIsMaster("Y");
        virtualUsage.setRelationInterfaceId(interfaceId);
        List<VirtualUsage> virtualUsages = this.virtualUsageService.selectVirtualUsageList(virtualUsage);
        if (CollectionUtil.isNotEmpty(virtualUsages)) {
            mmap.put("isMaster", "Y");
        }
        return prefix + "/data_map_choose";
    }

    @GetMapping("data_map_create/{isInParam}/{domainObjectId}/{interfaceId}/{type}")
    public String data_map_create(@PathVariable("isInParam") Long isInParam,
                                  @PathVariable("domainObjectId") Long domainObjectId,
                                  @PathVariable("interfaceId") Long interfaceId,
                                  @PathVariable("type") String type,
                                  ModelMap mmap) {
        mmap.put("isInParam", isInParam);
        mmap.put("interfaceId", interfaceId);
        mmap.put("type", type);
        DomainObjectInfo domainObjectInfo = this.domainInfoService.selectDomainObjectById(domainObjectId);
        if (domainObjectInfo != null) {
            mmap.put("objectEnName", domainObjectInfo.getObjectEnName());
            mmap.put("objectName", domainObjectInfo.getObjectName() + "列表");
        } else {
            mmap.put("objectEnName", "");
            mmap.put("objectName", "");
        }
        return prefix + "/data_map_create";
    }


    /**
     * 保存接口数据集
     * @param dubboParamReq
     * @return
     */
    @PostMapping("/saveInterfaceParams")
    @ResponseBody
    public AjaxResult saveInterfaceParams(DubboParamReq dubboParamReq) {
        interfaceInfoService.saveDubboParam(dubboParamReq);
        return success();
    }

    /**
     * 保存method接口字段
     * @param dubboParamReq
     * @return
     */
    @PostMapping("/saveMethodParam")
    @ResponseBody
    public AjaxResult saveMethodParam(DubboParamReq dubboParamReq) {
        interfaceInfoService.saveMethodParam(dubboParamReq);
        return success();
    }

    /**
     * bff接口详情
     * @param id
     * @return
     */
    @GetMapping("/bffDetail/{id}")
    public String bffDetail(@PathVariable("id") Long id, ModelMap mmap) {
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(id);
        mmap.put("interfaceInfo", interfaceInfo);
        List<InterfaceUser> interfaceUsers = this.userDataAuthService.selectInterfaceUser(id, "5");
        if (CollectionUtil.isNotEmpty(interfaceUsers)) {
            for (InterfaceUser interfaceUser : interfaceUsers) {
                if (ShiroUtils.getLoginName().equals(interfaceUser.getLoginName())) {
                    mmap.put("owner", true);
                    mmap.put("interfaceUser", interfaceUser);

                    if (interfaceUser.getObjectStatus() == 0) {
                        mmap.put("statusName", "未开始");
                    } else if (interfaceUser.getObjectStatus() == 1) {
                        mmap.put("statusName", "进行中");
                    } else if (interfaceUser.getObjectStatus() == 2) {
                        mmap.put("statusName", "已完成");
                    }
                    break;
                }
            }
        }
        return prefix + "/details";
    }

    /**
     * bff接口详情,异步
     * @param interfaceId
     * @return
     */
    @PostMapping("/interfaceDetail")
    @ResponseBody
    public AjaxResult ajaxBffDetail(@RequestParam Long interfaceId) {
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
        return AjaxResult.success(interfaceInfo);
    }



    /**
     * 接口参数列表
     * @param interfaceType 1实体用况method 2实体用况Bff接口 3 虚拟用况接口 4 Dubbo接口
     * @param interfaceId 接口id
     * @return
     */
    @PostMapping("/paramList")
    @ResponseBody
    public AjaxResult paramList(@RequestParam String interfaceType, @RequestParam Long interfaceId, @RequestParam(required = false) Long processBranchId, @RequestParam(required = false) Long virtualUsageGroupId) {
        Long id = interfaceId;
        List<InterfaceParam> requestList = this.interfaceInfoService.paramList(interfaceType, interfaceId, "1");
        if ("2".equals(interfaceType)) {
            loadFieldStatus(requestList);
        }
        loadFieldEnum(requestList);
        List<InterfaceParam> responseList = this.interfaceInfoService.paramList(interfaceType, interfaceId, "2");
        loadFieldEnum(responseList);
        String description = null;
        if ("3".equals(interfaceType)) {
            VirtualUsage virtualUsage = this.virtualUsageService.selectVirtualUsageById(interfaceId);
            interfaceId = virtualUsage.getInterfaceId();
            description = virtualUsage.getDescription();
        }
        InterfaceInfo interfaceInfo = null;
        if (!"5".equals(interfaceType)) {
            interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
            if ("Y".equals(interfaceInfo.getIsPage())) {
                if (!CollectionUtil.isNotEmpty(requestList)) {
                    requestList = new ArrayList<>();
                }
                InterfaceParam interfaceParam = new InterfaceParam();
                interfaceParam.setFieldEnName("pageNum");
                interfaceParam.setFieldName("当前页");
                interfaceParam.setMockData("1");
                requestList.add(interfaceParam);
                InterfaceParam interfaceParam2 = new InterfaceParam();
                interfaceParam2.setFieldEnName("pageSize");
                interfaceParam2.setFieldName("每页大小");
                interfaceParam2.setMockData("10");
                requestList.add(interfaceParam2);
                if (!CollectionUtil.isNotEmpty(responseList)) {
                    responseList = new ArrayList<>();
                }
                InterfaceParam interfaceParam3 = new InterfaceParam();
                interfaceParam3.setFieldEnName("total");
                interfaceParam3.setFieldName("总条数");
                interfaceParam3.setMockData("1000");
                responseList.add(interfaceParam3);
                InterfaceParam interfaceParam4 = new InterfaceParam();
                interfaceParam4.setFieldEnName("isLastPage");
                interfaceParam4.setFieldName("是否最后一页");
                interfaceParam4.setMockData("true");
                interfaceParam4.setObjectType("1");
                responseList.add(interfaceParam4);

                InterfaceParam interfaceParam5 = new InterfaceParam();
                interfaceParam5.setFieldEnName("pages");
                interfaceParam5.setFieldName("总页数");
                interfaceParam5.setMockData("10");
                interfaceParam5.setObjectType("1");
                responseList.add(interfaceParam5);
            }
            if ("3".equals(interfaceType)) {
                interfaceInfo.setInterfaceDescription(description == null ? "" : description);
                // 查询是否设置字段来源
                if (CollectionUtil.isNotEmpty(requestList)) {
                    List<Long> paramIds = new ArrayList<>();
                    List<Long> paramsFieldIds = new ArrayList<>();
                    for (InterfaceParam interfaceParam : requestList) {
                        if (interfaceParam.getId() != null) {
                            paramIds.add(interfaceParam.getId());
                            if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                                for (InterfaceParam child : interfaceParam.getChildren()) {
                                    paramsFieldIds.add(child.getId());
                                }
                            }
                        }
                    }
                    Map<Long, List<VirtualUsageParamSource>> collect = new HashMap<>();
                    Map<Long, List<VirtualUsageParamSource>> collect2 = new HashMap<>();
                    VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
                    if (paramIds.size() > 0) {
                        virtualUsageParamSource.setObjectIds(paramIds);
                        virtualUsageParamSource.setType("1");
                        virtualUsageParamSource.setProcessBranchId(processBranchId);
                        virtualUsageParamSource.setVirtualUsageGroupId(virtualUsageGroupId);
                        List<VirtualUsageParamSource> virtualUsageParamSources = virtualUsageParamSourceService.selectVirtualUsageParamSourceList2(virtualUsageParamSource);
                        if (CollectionUtil.isNotEmpty(virtualUsageParamSources)) {
                            collect = virtualUsageParamSources.stream().collect(Collectors.groupingBy(VirtualUsageParamSource::getObjectId));
                        }
                    }
                    if (paramsFieldIds.size() > 0) {
                        virtualUsageParamSource.setObjectIds(paramsFieldIds);
                        virtualUsageParamSource.setType("2");
                        virtualUsageParamSource.setProcessBranchId(processBranchId);
                        virtualUsageParamSource.setVirtualUsageGroupId(virtualUsageGroupId);
                        List<VirtualUsageParamSource> virtualUsageParamSources = virtualUsageParamSourceService.selectVirtualUsageParamSourceList2(virtualUsageParamSource);
                        if (CollectionUtil.isNotEmpty(virtualUsageParamSources)) {
                            collect2 = virtualUsageParamSources.stream().collect(Collectors.groupingBy(VirtualUsageParamSource::getObjectId));
                        }
                    }

                    for (InterfaceParam interfaceParam : requestList) {
                        if (interfaceParam.getId() != null) {
                            if (collect.containsKey(interfaceParam.getId())) {
                                interfaceParam.setSourceFlag("Y");
                            }
                            if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                                for (InterfaceParam child : interfaceParam.getChildren()) {
                                    if (collect2.containsKey(child.getId())) {
                                        child.setSourceFlag("Y");
                                    }
                                }
                            }
                        }
                    }
                }
                // 查询虚拟用况出参 字段融合数据
                if (CollectionUtil.isNotEmpty(responseList)) {
                    VirtualUsageFieldMerge virtualUsageFieldMerge = new VirtualUsageFieldMerge();
                    virtualUsageFieldMerge.setVirtualUsageId(id);
                    List<VirtualUsageFieldMerge> virtualUsageFieldMerges = this.virtualUsageFieldMergeService.selectVirtualUsageFieldMergeList(virtualUsageFieldMerge);
                    if (CollectionUtil.isNotEmpty(virtualUsageFieldMerges)) {
                        Map<Long, List<VirtualUsageFieldMerge>> collect = virtualUsageFieldMerges.stream().collect(Collectors.groupingBy(VirtualUsageFieldMerge::getObjectId));
                        for (InterfaceParam interfaceParam : responseList) {
                            if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                                for (InterfaceParam child : interfaceParam.getChildren()) {
                                    if (collect.containsKey(child.getId())) {
                                        child.setMergeFlag("Y");
                                    }
                                }
                            }
                        }
                    }
                }
            } else if ("2".equals(interfaceType) || "4".equals(interfaceType)) {
                VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
                virtualUsageParamSource.setInterfaceId(interfaceId);
                virtualUsageParamSource.setIsInParam("2");
                List<VirtualUsageParamSource> virtualUsageParamSourceList = this.virtualUsageParamSourceService.selectVirtualUsageParamSourceList(virtualUsageParamSource);
                if (CollectionUtil.isNotEmpty(virtualUsageParamSourceList)) {
                    Map<String, List<VirtualUsageParamSource>> record = new HashMap<>();
                    for (VirtualUsageParamSource paramSource : virtualUsageParamSourceList) {
                        List<VirtualUsageParamSource> virtualUsageParamSourceList1 = record.computeIfAbsent(paramSource.getObjectId() + paramSource.getType(), key -> new ArrayList<>());
                        virtualUsageParamSourceList1.add(paramSource);
                    }
                    if (CollectionUtil.isNotEmpty(responseList)) {
                        for (InterfaceParam interfaceParam : responseList) {
                            if (record.containsKey(interfaceParam.getId() + "1")) {
                                interfaceParam.setSourceFlag("Y");
                            }
                            if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                                for (InterfaceParam child : interfaceParam.getChildren()) {
                                    if (record.containsKey(child.getId() + "2")) {
                                        child.setSourceFlag("Y");
                                    }
                                }
                            }
                        }
                    }
                }
            } else if ("1".equals(interfaceType)) {
                if (CollectionUtil.isNotEmpty(requestList)) {
                    for (InterfaceParam interfaceParam : requestList) {
                        if ("Y".equals(interfaceParam.getIsRequired()) && "Y".equals(interfaceParam.getFieldIsRequired())) {
                            interfaceParam.setIsRequiredParent("Y");
                        } else {
                            interfaceParam.setIsRequiredParent("N");
                        }
                        if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                            for (InterfaceParam child : interfaceParam.getChildren()) {
                                if ("Y".equals(child.getIsRequired()) && "Y".equals(child.getFieldIsRequired())) {
                                    child.setIsRequiredParent("Y");
                                } else {
                                    child.setIsRequiredParent("N");
                                }
                            }
                        }
                    }
                }
            }
        } else {
            // 查询是否设置字段来源
            if (CollectionUtil.isNotEmpty(requestList)) {
                List<Long> paramIds = new ArrayList<>();
                List<Long> paramsFieldIds = new ArrayList<>();
                for (InterfaceParam interfaceParam : requestList) {
                    if (interfaceParam.getId() != null) {
                        paramIds.add(interfaceParam.getId());
                        if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                            for (InterfaceParam child : interfaceParam.getChildren()) {
                                paramsFieldIds.add(child.getId());
                            }
                        }
                    }
                }
                Map<Long, List<VirtualUsageParamSource>> collect = new HashMap<>();
                Map<Long, List<VirtualUsageParamSource>> collect2 = new HashMap<>();
                VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
                if (paramIds.size() > 0) {
                    virtualUsageParamSource.setObjectIds(paramIds);
                    virtualUsageParamSource.setType("1");
                    virtualUsageParamSource.setProcessBranchId(processBranchId);
                    List<VirtualUsageParamSource> virtualUsageParamSources = virtualUsageParamSourceService.selectVirtualUsageParamSourceList2(virtualUsageParamSource);
                    if (CollectionUtil.isNotEmpty(virtualUsageParamSources)) {
                        collect = virtualUsageParamSources.stream().collect(Collectors.groupingBy(VirtualUsageParamSource::getObjectId));
                    }
                }
                if (paramsFieldIds.size() > 0) {
                    virtualUsageParamSource.setObjectIds(paramsFieldIds);
                    virtualUsageParamSource.setType("2");
                    virtualUsageParamSource.setProcessBranchId(processBranchId);
                    List<VirtualUsageParamSource> virtualUsageParamSources = virtualUsageParamSourceService.selectVirtualUsageParamSourceList2(virtualUsageParamSource);
                    if (CollectionUtil.isNotEmpty(virtualUsageParamSources)) {
                        collect2 = virtualUsageParamSources.stream().collect(Collectors.groupingBy(VirtualUsageParamSource::getObjectId));
                    }
                }

                for (InterfaceParam interfaceParam : requestList) {
                    if (interfaceParam.getId() != null) {
                        if (collect.containsKey(interfaceParam.getId())) {
                            interfaceParam.setSourceFlag("Y");
                        }
                        if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                            for (InterfaceParam child : interfaceParam.getChildren()) {
                                if (collect2.containsKey(child.getId())) {
                                    child.setSourceFlag("Y");
                                }
                            }
                        }
                    }
                }
            }
        }
        return AjaxResult.success(new InterfaceParamVo(requestList, responseList, interfaceInfo));
    }

    /**
     * 关联字段
     * @param interfaceType 1实体用况Dubbo接口 2实体用况Bff接口 3 虚拟用况接口
     * @param interfaceId id
     * @return
     */
    @PostMapping("/fieldList")
    @ResponseBody
    public AjaxResult fieldList(@RequestParam String interfaceType, @RequestParam Long interfaceId) {
        List<FieldInfo> inFieldList = this.interfaceInfoService.fieldList(interfaceType, interfaceId, "1");
        List<FieldInfo> outFieldList = this.interfaceInfoService.fieldList(interfaceType, interfaceId, "2");
        return AjaxResult.success(new InterfaceFieldVo(inFieldList, outFieldList));
    }

    /**
     * 关联表
     * @param interfaceType 1实体用况Dubbo接口 2实体用况Bff接口 3 虚拟用况接口
     * @param interfaceId id
     * @return
     */
    @PostMapping("/tableList")
    @ResponseBody
    public AjaxResult tableList(@RequestParam String interfaceType, @RequestParam Long interfaceId) {
        List<TableInfo> tableInfos = this.interfaceInfoService.tableList(interfaceType, interfaceId);
        return AjaxResult.success(tableInfos);
    }

    @PostMapping("/interfaceTableList")
    @ResponseBody
    public AjaxResult interfaceTableList(@RequestParam String interfaceType, @RequestParam Long interfaceId) {
        List<TableInfo> tableInfos = this.interfaceInfoService.tableList(interfaceType, interfaceId);
        if (CollectionUtil.isNotEmpty(tableInfos)) {
            List<Long> tableIds = tableInfos.stream().map(TableInfo::getId).collect(Collectors.toList());
            tableInfos = this.tableInfoService.selectTableInfoByTableIds(tableIds);
        }
        return AjaxResult.success(tableInfos);
    }

    private IFileInfoService fileInfoService;

    /**
     * 关联页面
     * @param interfaceId id
     * @return
     */
    @PostMapping("/pageList")
    @ResponseBody
    public AjaxResult pageList(@RequestParam Long interfaceId) {
        //List<Page> pageList = this.pageService.pageListByInterfaceId(Collections.singletonList(interfaceId));
        // 查询接口关联的页面大图
        List<FileInf> pageFileList = this.pageService.selectPageFileByInterfaceId(interfaceId);
        FileInf fileInf = new FileInf();
        fileInf.setObjectId(interfaceId);
        fileInf.setObjectType("1");
        fileInf.setIsMaster(null);
        List<FileInf> interfaceFileList = this.fileInfoService.selectFileInfoList(fileInf);
        Map<String, Object> result = new HashMap<>();
        result.put("pageFileList", pageFileList);
        result.put("interfaceFileList", interfaceFileList);
        return AjaxResult.success(result);
    }

    /**
     *  接口局部图集合
     * @param interfaceId 接口ID
     * @return
     */
    @PostMapping("/imgList")
    @ResponseBody
    public AjaxResult imgList(@RequestParam Long interfaceId) {
        FileInf fileInf = new FileInf();
        fileInf.setObjectId(interfaceId);
        fileInf.setObjectType("1");
        fileInf.setIsMaster(null);
        List<FileInf> fileInfs = this.fileInfoService.selectFileInfoList(fileInf);
        return AjaxResult.success(fileInfs);
    }

    /**
     * 关联用况
     * @param interfaceId id
     * @return
     */
    @PostMapping("/usageList")
    @ResponseBody
    public AjaxResult usageList(@RequestParam Long interfaceId) {
        List<Usage> usageList = this.interfaceInfoService.selectUsageList(Collections.singletonList(interfaceId));
        return AjaxResult.success(usageList);
    }

    /**
     * 关联业务系统
     * @param interfaceType 1实体用况Dubbo接口 2实体用况Bff接口 3 虚拟用况接口
     * @param interfaceId id
     * @return
     */
    @PostMapping("/businessSystemList")
    @ResponseBody
    public AjaxResult businessSystemList(@RequestParam String interfaceType, @RequestParam Long interfaceId) {
        List<TableInfo> tableInfos = this.interfaceInfoService.tableList(interfaceType, interfaceId);
        List<BusinessSystem> businessSystems = null;
        if (CollectionUtil.isNotEmpty(tableInfos)) {
            Set<Long> tableIds = tableInfos.stream().map(TableInfo::getId).collect(Collectors.toSet());
            TableObject tableObject = new TableObject();
            tableObject.setObjectType("1");
            tableObject.setTableIds(tableIds);
            List<TableObject> tableObjects = this.tableObjectService.selectTableObjectList(tableObject);
            if (CollectionUtil.isNotEmpty(tableObjects)) {
                Set<Long> businessSystemIds = tableObjects.stream().map(TableObject::getObjectId).collect(Collectors.toSet());
                BusinessSystem businessSystem = new BusinessSystem();
                businessSystem.setBusinessSystemIds(businessSystemIds);
                businessSystems = businessSystemService.selectBusinessSystemList(businessSystem);
            }
        }
        return AjaxResult.success(businessSystems);
    }

    /**
     * 问题备注
     * @param objectId 关联id
     * @param objectType 关联对象类型 1. bff接口 2 表
     * @return
     */
    @PostMapping("/questionList")
    @ResponseBody
    public AjaxResult questionList(@RequestParam Long objectId,@RequestParam String objectType) {
        QuestionInfo questionInfo = new QuestionInfo();
        questionInfo.setObjectId(objectId);
        questionInfo.setObjectType(objectType);
        List<QuestionInfo> questionInfoList = this.questionInfoService.selectQuestionInfoList(questionInfo);
        return AjaxResult.success(questionInfoList);
    }

    @GetMapping("add_question/{objectId}/{objectType}")
    public String addQuestion(@PathVariable("objectId") Long objectId,@PathVariable("objectType") String objectType, ModelMap mmap) {
        mmap.put("objectId", objectId);
        mmap.put("objectType", objectType);
        return prefix + "/add_question";
    }

    /**
     * 表详情；
     * fieldInfoList ：字段信息列表
     * 在模型预览和字段属性展示
     * @param id 表id
     * @param mmap mmap
     * @return 表详情页面
     */
    @GetMapping("/table_detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        TableInfo tableInfo = this.tableInfoService.selectTableInfoById(id);
        mmap.put("tableInfo", tableInfo);
        List<InterfaceUser> interfaceUsers = this.userDataAuthService.selectInterfaceUser(id, "4");
        if (CollectionUtil.isNotEmpty(interfaceUsers)) {
            for (InterfaceUser interfaceUser : interfaceUsers) {
                if (ShiroUtils.getLoginName().equals(interfaceUser.getLoginName())) {
                    mmap.put("owner", true);
                    mmap.put("interfaceUser", interfaceUser);

                    if (interfaceUser.getObjectStatus() == 0) {
                        mmap.put("statusName", "未开始");
                    } else if (interfaceUser.getObjectStatus() == 1) {
                        mmap.put("statusName", "进行中");
                    } else if (interfaceUser.getObjectStatus() == 2) {
                        mmap.put("statusName", "已完成");
                    }
                    break;
                }
            }
        }
        return prefix + "/table_detail";
    }

    /**
     * 查询虚拟用况
     * @param interfaceId
     * @return
     */
    @PostMapping("/virtualUsageList")
    @ResponseBody
    public AjaxResult virtualUsageList(@RequestParam Long interfaceId) {
        VirtualUsage virtualUsage = new VirtualUsage();
        virtualUsage.setRelationInterfaceId(interfaceId);
        List<VirtualUsage> virtualUsages = this.virtualUsageService.selectVirtualUsages(virtualUsage);
        return AjaxResult.success(virtualUsages);
    }

    /**
     * dubbo 选择页
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/bff_dubbo_choose/{id}")
    public String bff_dubbo_choose(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("id", id);
        return prefix + "/bff_dubbo_choose";
    }

    /**
     * 方法 选择页
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/method_choose/{id}/{appType}")
    public String method_choose(@PathVariable("id") Long id, @PathVariable("appType") String appType, ModelMap mmap) {
        mmap.put("id", id);
        mmap.put("appType", appType);
        return prefix + "/method_choose";
    }

    /**
     * 查询dubbo接口
     * @param interfaceInfo
     * @return
     */
    @PostMapping("/dubboList")
    @ResponseBody
    public AjaxResult dubboList(InterfaceInfo interfaceInfo) {
        interfaceInfo.setExcludeFlag("1");
        InterfaceInfo info = this.interfaceInfoService.selectInterfaceInfoById(interfaceInfo.getId());
        if ("3".equals(info.getFbType())) {
            interfaceInfo.setIsCommon("Y");
            //interfaceInfo.setNotAppType(info.getAppType());
        }
        List<InterfaceInfo> dubboList = this.interfaceInfoService.dubboList(interfaceInfo);
        return AjaxResult.success(dubboList);
    }

    /**
     * 查询方法
     * @param interfaceInfo
     * @return
     */
    @PostMapping("/methodList")
    @ResponseBody
    public AjaxResult methodList(InterfaceInfo interfaceInfo) {
        interfaceInfo.setExcludeFlag("1");
        List<InterfaceInfo> methodList = this.interfaceInfoService.dubboList(interfaceInfo);
        return AjaxResult.success(methodList);
    }

    /**
     * 保存虚拟用况
     * @param virtualUsageReq
     * @return
     */
    @PostMapping("/saveVirtualUsageNew")
    @ResponseBody
    public AjaxResult saveVirtualUsageNew(VirtualUsageReq virtualUsageReq) {
        this.virtualUsageService.saveVirtualUsageNew(virtualUsageReq);
        return success();
    }

    /**
     * 虚拟用况接口详情
     * @param id
     * @return
     */
    @GetMapping("/bff_usage_params/{id}")
    public String bff_usage_params(@PathVariable("id") Long id, ModelMap mmap) {
        VirtualUsage virtualUsage = new VirtualUsage();
        virtualUsage.setId(id);
        List<VirtualUsage> virtualUsages = this.virtualUsageService.selectVirtualUsages(virtualUsage);
        VirtualUsage usage = virtualUsages.get(0);
        mmap.put("virtualUsage", usage);
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(usage.getRelationInterfaceId());
        mmap.put("interfaceInfo", interfaceInfo);


        DomainInfo domainInfo = new DomainInfo();
        List<DomainInfo> domainInfos = this.domainInfoService.selectDomainInfoList(domainInfo);
        mmap.put("domainInfoList", domainInfos);
        List<DomainObjectInfo> domainObjectInfos = new ArrayList<>();
        Long domainId = usage.getDomainId();
        if (domainId == null) {
            InterfaceInfo info = this.interfaceInfoService.selectInterfaceInfoById(usage.getInterfaceId());
            domainId = info.getDomainId();
            usage.setDomainId(domainId);
            usage.setDomainObjectId(info.getDomainObjectId());
        }
        DomainInfo domainInfo1 = this.domainInfoService.selectDomainInfoById(domainId);
        if (domainInfo1 != null && domainInfo1.getDomainObjectInfoList() != null) {
            domainObjectInfos = domainInfo1.getDomainObjectInfoList();
        }
        mmap.put("domainObjectList", domainObjectInfos);
        return prefix + "/bff_usage_params";
    }

    @PostMapping("/editVirtualUsage")
    @ResponseBody
    public AjaxResult editVirtualUsage(VirtualUsage virtualUsage) {
//        VirtualUsage usage = this.virtualUsageService.selectVirtualUsageById(virtualUsage.getId());
//        if ("Y".equals(virtualUsage.getIsMaster())) {
//            VirtualUsage vu = new VirtualUsage();
//            vu.setRelationInterfaceId(usage.getRelationInterfaceId());
//            vu.setIsMaster("Y");
//            List<VirtualUsage> virtualUsages = this.virtualUsageService.selectVirtualUsageList(vu);
//            if (CollectionUtil.isNotEmpty(virtualUsages)) {
//                for (VirtualUsage virtualUsage1 : virtualUsages) {
//                    if (!virtualUsage1.getId().equals(virtualUsage.getId())) {
//                        return AjaxResult.warn("其它虚拟用况已设置主");
//                    }
//                }
//            }
//        }
        this.virtualUsageService.updateVirtualUsage(virtualUsage);
        return success();
    }

    /**
     * 虚拟用况选择字段
     * @param id 虚拟用况id
     * @param dubboId dubboId
     * @param isInParam 1-入 2-出
     * @param mmap mmap
     * @return
     */
    @GetMapping("/usage_field_choose/{id}/{dubboId}/{isInParam}/{fbType}")
    public String usage_field_choose(@PathVariable("id") Long id, @PathVariable("dubboId") Long dubboId, @PathVariable("isInParam") String isInParam, @PathVariable("fbType") String fbType, ModelMap mmap) {
        mmap.put("interfaceId", id);
        mmap.put("dubboId", dubboId);
        mmap.put("isInParam", isInParam);
        if ("3".equals(fbType)) {
            fbType = "4";
        }
        mmap.put("fbType", fbType);
        ListInterfaceFieldParamReq listInterfaceFieldParamReq = new ListInterfaceFieldParamReq();
        listInterfaceFieldParamReq.setType("3");
        listInterfaceFieldParamReq.setInterfaceId(id);
        listInterfaceFieldParamReq.setIsInParam(isInParam);
        List<InterfaceParam> listFieldParam = this.interfaceInfoService.listInterfaceFieldParam(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(listFieldParam)) {
            List<Long> fieldIds = listFieldParam.stream().map(InterfaceParam::getFieldId).collect(Collectors.toList());
            mmap.put("fieldIds", fieldIds);
        } else {
            mmap.put("fieldIds", new ArrayList<Long>());
        }
        return prefix + "/usage_field_choose";
    }

    /**
     * 查询接口字段数据
     * @param listInterfaceFieldParamReq
     * @return
     */
    @PostMapping("/listInterfaceFieldParam")
    @ResponseBody
    public AjaxResult listInterfaceFieldParam(ListInterfaceFieldParamReq listInterfaceFieldParamReq) {
        List<InterfaceParam> listInterfaceFieldParam = this.interfaceInfoService.listInterfaceFieldParam(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(listInterfaceFieldParam)) {
            listInterfaceFieldParam.removeIf(next -> StringUtils.isNotEmpty(next.getDesignContent()));
        }
        return AjaxResult.success(listInterfaceFieldParam);
    }

    /**
     * 保存虚拟用况参数
     * @param virtualUsageParamReq
     * @return
     */
    @PostMapping("/saveVirtualUsageParam")
    @ResponseBody
    public AjaxResult saveVirtualUsageParam(VirtualUsageParamReq virtualUsageParamReq) {
        if (virtualUsageParamReq.getInterfaceParamsFieldRelationId() != null) {
            // 保存数据集与字段关系
            this.paramsFieldRelationService.saveVirtualUsageParam(virtualUsageParamReq);
        } else {
            // 保存接口和字段或者数据集关系
            this.interfaceParamsFieldRelationService.saveVirtualUsageParam(virtualUsageParamReq);
        }
        return success();
    }

    /**
     * 虚拟用况选择字段
     * @param id 虚拟用况id
     * @param dubboId dubboId
     * @param isInParam 1-入 2-出
     * @param mmap mmap
     * @return
     */
    @GetMapping("/usage_data_map_choose/{id}/{dubboId}/{isInParam}/{fbType}")
    public String usage_data_map_choose(@PathVariable("id") Long id,
                                        @PathVariable("dubboId") Long dubboId,
                                        @PathVariable("isInParam") String isInParam,
                                        @PathVariable("fbType") String fbType,
                                        ModelMap mmap) {
        ListInterfaceFieldParamReq listInterfaceFieldParamReq = new ListInterfaceFieldParamReq();
        listInterfaceFieldParamReq.setType("3");
        listInterfaceFieldParamReq.setInterfaceId(id);
        listInterfaceFieldParamReq.setIsInParam(isInParam);
        List<InterfaceParam> listFieldParam = this.interfaceInfoService.listInterfaceParams(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(listFieldParam)) {
            List<Long> fieldIds = listFieldParam.stream().map(InterfaceParam::getFieldId).collect(Collectors.toList());
            mmap.put("fieldIds", fieldIds);
        } else {
            mmap.put("fieldIds", new ArrayList<Long>());
        }
        mmap.put("interfaceId", id);
        mmap.put("dubboId", dubboId);
        mmap.put("isInParam", isInParam);
        if (fbType.equals("3")) {
            fbType = "4";
        }
        mmap.put("fbType", fbType);
        return prefix + "/usage_data_map_choose";
    }

    /**
     * 查询接口数据集
     * @param listInterfaceFieldParamReq
     * @return
     */
    @PostMapping("/listInterfaceParams")
    @ResponseBody
    public AjaxResult listInterfaceParams(ListInterfaceFieldParamReq listInterfaceFieldParamReq) {
        List<InterfaceParam> listInterfaceFieldParam = this.interfaceInfoService.listInterfaceParams(listInterfaceFieldParamReq);
        return AjaxResult.success(listInterfaceFieldParam);
    }

    /**
     * 虚拟用况数据集字段选择页面
     * @param id
     * @param dubboId
     * @param interfaceParamsFieldRelationId
     * @param mmap
     * @return
     */
    @GetMapping("/usage_params_field_choose/{id}/{dubboId}/{interfaceParamsFieldRelationId}/{fbType}")
    public String usage_params_field_choose(@PathVariable("id") Long id,
                                            @PathVariable("dubboId") Long dubboId,
                                            @PathVariable("interfaceParamsFieldRelationId") Long interfaceParamsFieldRelationId,
                                            @PathVariable("fbType") String fbType,
                                            ModelMap mmap) {
        mmap.put("interfaceId", id);
        mmap.put("dubboId", dubboId);
        mmap.put("interfaceParamsFieldRelationId", interfaceParamsFieldRelationId);
        if (fbType.equals("3")) {
            fbType = "4";
        }
        mmap.put("fbType", fbType);
        InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(interfaceParamsFieldRelationId);
        mmap.put("interfaceParamsFieldRelation", interfaceParamsFieldRelation);
        ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
        paramsFieldRelation.setInterfaceDataListId(interfaceParamsFieldRelationId);
        List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationService.selectParamsFieldRelationList(paramsFieldRelation);
        if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
            List<Long> fieldIds = paramsFieldRelationList.stream().map(ParamsFieldRelation::getFieldId).collect(Collectors.toList());
            mmap.put("fieldIds", fieldIds);
        } else {
            mmap.put("fieldIds", new ArrayList<Long>());
        }
        return prefix + "/usage_params_field_choose";
    }

    /**
     * 查询接口字段数据
     * @param listInterfaceFieldParamReq
     * @return
     */
    @PostMapping("/listInterfaceParamsField")
    @ResponseBody
    public AjaxResult listInterfaceParamsField(ListInterfaceFieldParamReq listInterfaceFieldParamReq) {
        List<InterfaceParam> listInterfaceParamsField = this.interfaceInfoService.listInterfaceParamsField(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(listInterfaceParamsField)) {
            listInterfaceParamsField.removeIf(next -> StringUtils.isNotEmpty(next.getDesignContent()));
        }
        return AjaxResult.success(listInterfaceParamsField);
    }

    /**
     * bff接口参数列表
     * @param interfaceId 接口id
     * @return
     */
    @PostMapping("/bffParamList")
    @ResponseBody
    public AjaxResult bffParamList(@RequestParam Long interfaceId, @RequestParam(required = false) Long pageId, @RequestParam(required = false) Long pageImageId) {
        List<InterfaceParam> requestList = this.interfaceInfoService.paramList("2", interfaceId, "1");
        loadFieldStatus(requestList);
        loadFieldEnum(requestList);
        List<InterfaceParam> responseList = this.interfaceInfoService.paramList("2", interfaceId, "2");
        //loadFieldStatus(responseList);
        loadFieldEnum(responseList);

        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
        if ("Y".equals(interfaceInfo.getIsPage())) {
            if (!CollectionUtil.isNotEmpty(requestList)) {
                requestList = new ArrayList<>();
            }
            InterfaceParam interfaceParam = new InterfaceParam();
            interfaceParam.setFieldEnName("pageNum");
            interfaceParam.setFieldName("当前页");
            interfaceParam.setMockData("1");
            requestList.add(interfaceParam);
            InterfaceParam interfaceParam2 = new InterfaceParam();
            interfaceParam2.setFieldEnName("pageSize");
            interfaceParam2.setFieldName("每页大小");
            interfaceParam2.setMockData("10");
            requestList.add(interfaceParam2);
            if (!CollectionUtil.isNotEmpty(responseList)) {
                responseList = new ArrayList<>();
            }
            InterfaceParam interfaceParam3 = new InterfaceParam();
            interfaceParam3.setFieldEnName("total");
            interfaceParam3.setFieldName("总条数");
            interfaceParam3.setMockData("1000");
            responseList.add(interfaceParam3);
            InterfaceParam interfaceParam4 = new InterfaceParam();
            interfaceParam4.setFieldEnName("isLastPage");
            interfaceParam4.setFieldName("是否最后一页");
            interfaceParam4.setMockData("true");
            interfaceParam4.setObjectType("1");
            responseList.add(interfaceParam4);
            InterfaceParam interfaceParam5 = new InterfaceParam();
            interfaceParam5.setFieldEnName("pages");
            interfaceParam5.setFieldName("总页数");
            interfaceParam5.setMockData("10");
            interfaceParam5.setObjectType("1");
            responseList.add(interfaceParam5);
        }
        // 出参来源
        VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
        virtualUsageParamSource.setInterfaceId(interfaceId);
        virtualUsageParamSource.setIsInParam("2");
        List<VirtualUsageParamSource> virtualUsageParamSourceList = this.virtualUsageParamSourceService.selectVirtualUsageParamSourceList(virtualUsageParamSource);
        if (CollectionUtil.isNotEmpty(virtualUsageParamSourceList)) {
            Map<String, List<VirtualUsageParamSource>> record = new HashMap<>();
            for (VirtualUsageParamSource paramSource : virtualUsageParamSourceList) {
                List<VirtualUsageParamSource> virtualUsageParamSourceList1 = record.computeIfAbsent(paramSource.getObjectId() + paramSource.getType(), key -> new ArrayList<>());
                virtualUsageParamSourceList1.add(paramSource);
            }
            if (CollectionUtil.isNotEmpty(responseList)) {
                for (InterfaceParam interfaceParam : responseList) {
                    if (record.containsKey(interfaceParam.getId() + "1")) {
                        interfaceParam.setSourceFlag("Y");
                    }
                    if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                        for (InterfaceParam child : interfaceParam.getChildren()) {
                            if (record.containsKey(child.getId() + "2")) {
                                child.setSourceFlag("Y");
                            }
                        }
                    }
                }
            }
        }
        if (CollectionUtil.isNotEmpty(requestList)) {
            // 查询前端入参来源
            if (pageId != null && pageImageId != null) {
                FrontInterfaceFieldSource frontInterfaceFieldSource = new FrontInterfaceFieldSource();
                frontInterfaceFieldSource.setPageId(pageId);
                frontInterfaceFieldSource.setPageImgId(pageImageId);
                frontInterfaceFieldSource.setInterfaceId(interfaceId);
                List<FrontInterfaceFieldSource> frontInterfaceFieldSources = this.frontInterfaceFieldSourceService.selectFrontInterfaceFieldSourceList(frontInterfaceFieldSource);
                if (CollectionUtil.isNotEmpty(frontInterfaceFieldSources)) {
                    Map<String, FrontInterfaceFieldSource> map = new HashMap<>();
                    for (FrontInterfaceFieldSource interfaceFieldSource : frontInterfaceFieldSources) {
                        map.put(interfaceFieldSource.getObjectId() + interfaceFieldSource.getObjectType(), interfaceFieldSource);
                    }

                    handlerFrontFieldSource(requestList, "1", map);
                }
            }
        }
        return AjaxResult.success(new InterfaceParamVo(requestList, responseList, interfaceInfo));
    }

    private void handlerFrontFieldSource(List<InterfaceParam> requestList, String type, Map<String, FrontInterfaceFieldSource> map) {
        List<SysDictData> sysDictDataList = sysDictTypeService.selectDictDataByType("storageType");
        Map<String, List<SysDictData>> collect = sysDictDataList.stream().collect(Collectors.groupingBy(SysDictData::getDictValue));
        for (InterfaceParam interfaceParam : requestList) {
            FrontInterfaceFieldSource fieldSource = map.get(interfaceParam.getId() + type);
            if (fieldSource != null) {
                interfaceParam.setFrontFieldRemark(fieldSource.getRemark());
                StringBuilder fieldSourceStr = new StringBuilder("来源于");
                if (fieldSource.getSourceType().equals("1")) {
                    fieldSourceStr.append("接口 ").append(fieldSource.getSourceInterfaceUrl());
                    if (fieldSource.getSourceObjectFieldName() != null) {
                        fieldSourceStr.append(" 的数据集").append(fieldSource.getSourceObjectName()).append("下字段").append(fieldSource.getSourceObjectFieldName());
                    } else {
                        fieldSourceStr.append(" 的字段").append(fieldSource.getSourceObjectName());
                    }

                    if ("Y".equals(fieldSource.getIsPageStore())) {
                        fieldSourceStr.append(" 是页面store");
                    }
                } else if (fieldSource.getSourceType().equals("2")) {
                    fieldSourceStr.append("约定值 ");
                    if (fieldSource.getContractValueType().equals("0")) {
                        fieldSourceStr.append("类型").append(fieldSource.getDictType());
                    } else if (fieldSource.getContractValueType().equals("1")) {
                        fieldSourceStr.append("类型编码").append(fieldSource.getDictValue());
                    } else if (fieldSource.getContractValueType().equals("2")) {
                        fieldSourceStr.append("关联表名").append(fieldSource.getTableOrFieldName());
                    } else if (fieldSource.getContractValueType().equals("3")) {
                        fieldSourceStr.append("关联表主键名").append(fieldSource.getTableOrFieldName());
                    } else if (fieldSource.getContractValueType().equals("4")) {
                        fieldSourceStr.append("对象属性code ");
                        if (fieldSource.getSourceObjectFieldName() != null) {
                            fieldSourceStr.append("数据集").append(fieldSource.getSourceObjectName()).append("下字段").append(fieldSource.getSourceObjectFieldName());
                        } else {
                            fieldSourceStr.append("字段").append(fieldSource.getSourceObjectName());
                        }
                    } else {
                        fieldSourceStr.append("固定值 ").append(fieldSource.getContractValue());
                    }
                } else if (fieldSource.getSourceType().equals("3")) {
                    List<SysDictData> sysDictData = collect.get(fieldSource.getStorageType());
                    fieldSourceStr.append("前端本地 " + sysDictData.get(0).getDictLabel() + "中接口 ").append(fieldSource.getSourceInterfaceUrl());
                    if (fieldSource.getSourceObjectFieldName() != null) {
                        fieldSourceStr.append(" 的数据集").append(fieldSource.getSourceObjectName()).append("下字段").append(fieldSource.getSourceObjectFieldName());
                    } else {
                        fieldSourceStr.append(" 的字段").append(fieldSource.getSourceObjectName());
                    }
                }
                interfaceParam.setFrontFieldSource(fieldSourceStr.toString());
            }
            if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                this.handlerFrontFieldSource(interfaceParam.getChildren(), "2", map);
            }
        }
    }

    private IFieldEnumService fieldEnumService;

    /**
     * 加载字段的枚举集合
     * @param params
     */
    private void loadFieldEnum(List<InterfaceParam> params) {
        if (CollectionUtil.isNotEmpty(params)) {
            List<Long> fieldIds = new ArrayList<>();
            for (InterfaceParam interfaceParam : params) {
                if ("1".equals(interfaceParam.getObjectType())) {
                    fieldIds.add(interfaceParam.getFieldId());
                }
                if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                    for (InterfaceParam child : interfaceParam.getChildren()) {
                        fieldIds.add(child.getFieldId());
                    }
                }
            }
            if (fieldIds.size() > 0) {
                List<FieldEnum> fieldEnumList = fieldEnumService.selectFieldEnumListByFieldIds(fieldIds);
                if (CollectionUtil.isNotEmpty(fieldEnumList)) {
                    Map<Long, List<FieldEnum>> collect = fieldEnumList.stream().collect(Collectors.groupingBy(FieldEnum::getFieldId));
                    for (InterfaceParam interfaceParam : params) {
                        if ("1".equals(interfaceParam.getObjectType())) {
                            setFieldEnumListName(collect, interfaceParam);
                        }
                        if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                            for (InterfaceParam child : interfaceParam.getChildren()) {
                                setFieldEnumListName(collect, child);
                            }
                        }
                    }
                }
            }
        }
    }

    private void setFieldEnumListName(Map<Long, List<FieldEnum>> collect, InterfaceParam interfaceParam) {
        List<FieldEnum> fieldStatusList1 = collect.get(interfaceParam.getFieldId());
        if (CollectionUtil.isNotEmpty(fieldStatusList1)) {
            StringBuilder fieldEnumListName = new StringBuilder();
            for (FieldEnum fieldEnum1 : fieldStatusList1) {
                if (fieldEnum1.getEnumName().equals(interfaceParam.getStatusName())) {
                    fieldEnumListName.append("<span style=\"color: red; display: inline !important;\">" + fieldEnum1.getEnumValue() + "-" + fieldEnum1.getEnumName() + "</span> ");
                } else {
                    fieldEnumListName.append(fieldEnum1.getEnumValue() + "-" + fieldEnum1.getEnumName() + " ");
                }

            }
            interfaceParam.setFieldEnumListName("(" + fieldEnumListName.toString() + ")");
        }
    }

    /**
     * 加载字段的状态集合
     * @param params
     */
    private void loadFieldStatus(List<InterfaceParam> params) {
        if (CollectionUtil.isNotEmpty(params)) {
            List<Long> fieldIds = new ArrayList<>();
            for (InterfaceParam interfaceParam : params) {
                if ("1".equals(interfaceParam.getObjectType())) {
                    fieldIds.add(interfaceParam.getFieldId());
                }
            }
            if (fieldIds.size() > 0) {
                FieldStatus fieldStatus = new FieldStatus();
                fieldStatus.setFieldIds(fieldIds);
                List<FieldStatus> fieldStatusList = this.fieldStatusService.selectFieldStatusList(fieldStatus);
                if (CollectionUtil.isNotEmpty(fieldStatusList)) {
                    Map<Long, List<FieldStatus>> collect = fieldStatusList.stream().collect(Collectors.groupingBy(FieldStatus::getFieldId));
                    for (InterfaceParam interfaceParam : params) {
                        if ("1".equals(interfaceParam.getObjectType())) {
                            List<FieldStatus> fieldStatusList1 = collect.get(interfaceParam.getFieldId());
                            if (CollectionUtil.isNotEmpty(fieldStatusList1)) {
                                for (FieldStatus status : fieldStatusList1) {
                                    if (status.getId().equals(interfaceParam.getStatusId())) {
                                        interfaceParam.setStatusName(status.getStatusZhName());
                                        status.setSelected(true);
                                        break;
                                    }
                                }
                            }
                            interfaceParam.setFieldStatusList(fieldStatusList1);
                        }
                    }
                }
            }
        }
    }

    /**
     * bff接口 字段参数选择页面
     * @param interfaceId 接口id
     * @param isInParam 1 入参 2 出参
     * @param mmap mmap
     * @return
     */
    @GetMapping("bff_field_choose/{interfaceId}/{isInParam}")
    public String bff_field_choose(@PathVariable("interfaceId") Long interfaceId,
                                     @PathVariable("isInParam") String isInParam,
                                     ModelMap mmap) {
        mmap.put("interfaceId", interfaceId);
        mmap.put("isInParam", isInParam);
        Set<Long> vuIds = new HashSet<>();
        List<Long> groupIds = new ArrayList<>();
        Set<Long> detailVuIds = new HashSet<>();
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
        if ("Y".equals(interfaceInfo.getIsBranch())) {
            ProcessBranch processBranch = new ProcessBranch();
            processBranch.setInterfaceId(interfaceId);
            List<ProcessBranch> processBranches = this.processBranchService.selectProcessBranchList(processBranch);
            if (CollectionUtil.isNotEmpty(processBranches)) {
                for (ProcessBranch branch : processBranches) {
                    if ("1".equals(branch.getType())) {
                        vuIds.add(branch.getEntityId());
                    } else if ("4".equals(branch.getType())) {
                        groupIds.add(branch.getEntityId());
                    }
                }
            }

            VirtualUsageGroupDetail virtualUsageGroupDetail = new VirtualUsageGroupDetail();
            virtualUsageGroupDetail.setInterfaceId(interfaceId);
            List<VirtualUsageGroupDetail> virtualUsageGroupDetailList = this.virtualUsageGroupDetailService.selectVirtualUsageGroupDetailList(virtualUsageGroupDetail);
            if (CollectionUtil.isNotEmpty(virtualUsageGroupDetailList)) {
                detailVuIds = virtualUsageGroupDetailList.stream().map(VirtualUsageGroupDetail::getVirtualUsageId).collect(Collectors.toSet());
            }
        }
        VirtualUsage virtualUsage = new VirtualUsage();
        virtualUsage.setRelationInterfaceId(interfaceId);
        List<VirtualUsage> virtualUsageList = this.virtualUsageService.selectVirtualUsages(virtualUsage);
        if (CollectionUtil.isNotEmpty(virtualUsageList) && "Y".equals(interfaceInfo.getIsBranch())) {
            List<VirtualUsage> excludes = new ArrayList<>();
            Iterator<VirtualUsage> iterator = virtualUsageList.iterator();
            while (iterator.hasNext()) {
                VirtualUsage next = iterator.next();
                if (!vuIds.contains(next.getId())) {
                    excludes.add(next);
                    iterator.remove();
                }
            }
            // 将不在分支下的虚拟用况和不在组里的虚拟用况加入进去
            if (excludes.size() > 0) {
                for (VirtualUsage exclude : excludes) {
                    if (!detailVuIds.contains(exclude.getId())) {
                        virtualUsageList.add(exclude);
                    }
                }
            }
        }
        ListInterfaceFieldParamReq listInterfaceFieldParamReq = new ListInterfaceFieldParamReq();
        listInterfaceFieldParamReq.setType("2");
        listInterfaceFieldParamReq.setInterfaceId(interfaceId);
        listInterfaceFieldParamReq.setIsInParam(isInParam);
        List<InterfaceParam> listFieldParam = this.interfaceInfoService.listInterfaceFieldParam(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(virtualUsageList)) {
            virtualUsageList.forEach(o -> {
                o.setVirtualUsageType("3");
            });
        }

        if (groupIds.size() > 0) {
            VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
            virtualUsageGroup.setInterfaceId(interfaceId);
            virtualUsageGroup.setIds(groupIds);
            List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
            if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
                virtualUsageGroups.forEach( o -> {
                    VirtualUsage virtualUsage1 = new VirtualUsage();
                    virtualUsage1.setSlaveInterfaceName(o.getGroupName());
                    virtualUsage1.setId(o.getId());
                    virtualUsage1.setVirtualUsageType("5");
                    virtualUsage1.setIsMaster(o.getIsMaster());
                    virtualUsageList.add(virtualUsage1);
                });
            }
        }

        for (VirtualUsage usage : virtualUsageList) {
            if ("Y".equals(usage.getIsMaster())) {
                usage.setSlaveInterfaceName(usage.getSlaveInterfaceName()+" （主）");
            }
        }
        mmap.put("listFieldParam", listFieldParam);
        mmap.put("virtualUsageList", virtualUsageList);
        return prefix + "/bff_field_choose";
    }

    /**
     * dubbo接口 字段参数选择页面
     * @param interfaceId 接口id
     * @param isInParam 1 入参 2 出参
     * @param mmap mmap
     * @return
     */
    @GetMapping("dubbo_field_choose/{interfaceId}/{isInParam}")
    public String dubbo_field_choose(@PathVariable("interfaceId") Long interfaceId,
                                   @PathVariable("isInParam") String isInParam,
                                   ModelMap mmap) {
        mmap.put("interfaceId", interfaceId);
        mmap.put("isInParam", isInParam);
        Set<Long> vuIds = new HashSet<>();
        List<Long> groupIds = new ArrayList<>();
        Set<Long> detailVuIds = new HashSet<>();
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
        if ("Y".equals(interfaceInfo.getIsBranch())) {
            ProcessBranch processBranch = new ProcessBranch();
            processBranch.setInterfaceId(interfaceId);
            List<ProcessBranch> processBranches = this.processBranchService.selectProcessBranchList(processBranch);
            if (CollectionUtil.isNotEmpty(processBranches)) {
                for (ProcessBranch branch : processBranches) {
                    if ("1".equals(branch.getType())) {
                        vuIds.add(branch.getEntityId());
                    } else if ("4".equals(branch.getType())) {
                        groupIds.add(branch.getEntityId());
                    }
                }
            }

            VirtualUsageGroupDetail virtualUsageGroupDetail = new VirtualUsageGroupDetail();
            virtualUsageGroupDetail.setInterfaceId(interfaceId);
            List<VirtualUsageGroupDetail> virtualUsageGroupDetailList = this.virtualUsageGroupDetailService.selectVirtualUsageGroupDetailList(virtualUsageGroupDetail);
            if (CollectionUtil.isNotEmpty(virtualUsageGroupDetailList)) {
                detailVuIds = virtualUsageGroupDetailList.stream().map(VirtualUsageGroupDetail::getVirtualUsageId).collect(Collectors.toSet());
            }
        }
        VirtualUsage virtualUsage = new VirtualUsage();
        virtualUsage.setRelationInterfaceId(interfaceId);
        List<VirtualUsage> virtualUsageList = this.virtualUsageService.selectVirtualUsages(virtualUsage);
        if (CollectionUtil.isNotEmpty(virtualUsageList) && "Y".equals(interfaceInfo.getIsBranch())) {
            List<VirtualUsage> excludes = new ArrayList<>();
            Iterator<VirtualUsage> iterator = virtualUsageList.iterator();
            while (iterator.hasNext()) {
                VirtualUsage next = iterator.next();
                if (!vuIds.contains(next.getId())) {
                    excludes.add(next);
                    iterator.remove();
                }
            }
            // 将不在分支下的虚拟用况和不在组里的虚拟用况加入进去
            if (excludes.size() > 0) {
                for (VirtualUsage exclude : excludes) {
                    if (!detailVuIds.contains(exclude.getId())) {
                        virtualUsageList.add(exclude);
                    }
                }
            }
        }
        ListInterfaceFieldParamReq listInterfaceFieldParamReq = new ListInterfaceFieldParamReq();
        listInterfaceFieldParamReq.setType("4");
        listInterfaceFieldParamReq.setInterfaceId(interfaceId);
        listInterfaceFieldParamReq.setIsInParam(isInParam);
        List<InterfaceParam> listFieldParam = this.interfaceInfoService.listInterfaceFieldParam(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(virtualUsageList)) {
            virtualUsageList.forEach(o -> {
                o.setVirtualUsageType("3");
            });
        }

        if (groupIds.size() > 0) {
            VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
            virtualUsageGroup.setInterfaceId(interfaceId);
            virtualUsageGroup.setIds(groupIds);
            List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
            if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
                virtualUsageGroups.forEach( o -> {
                    VirtualUsage virtualUsage1 = new VirtualUsage();
                    virtualUsage1.setSlaveInterfaceName(o.getGroupName());
                    virtualUsage1.setId(o.getId());
                    virtualUsage1.setVirtualUsageType("5");
                    virtualUsage1.setIsMaster(o.getIsMaster());
                    virtualUsageList.add(virtualUsage1);
                });
            }
        }

        for (VirtualUsage usage : virtualUsageList) {
            if ("Y".equals(usage.getIsMaster())) {
                usage.setSlaveInterfaceName(usage.getSlaveInterfaceName()+" （主）");
            }
        }
        mmap.put("listFieldParam", listFieldParam);
        mmap.put("virtualUsageList", virtualUsageList);
        return prefix + "/dubbo_field_choose";
    }

    /**
     * 查询接口所有字段包括数据集字段
     * @param listInterfaceFieldParamReq
     * @return
     */
    @PostMapping("/listInterfaceALlField")
    @ResponseBody
    public AjaxResult listInterfaceALlField(ListInterfaceFieldParamReq listInterfaceFieldParamReq) {
        PageMethod.clearPage();
        return AjaxResult.success(this.interfaceParamsFieldRelationService.listInterfaceALlField(listInterfaceFieldParamReq));
    }

    /**
     * 保存dubbo接口参数
     * @param bffParamReq
     * @return
     */
    @PostMapping("/saveDubboParam")
    @ResponseBody
    public AjaxResult saveDubboParam(BffParamReq bffParamReq) {
        String[] fieldInfos = bffParamReq.getFieldInfo().split(",");
        List<Long> interfaceParamsFieldRelationIds = new ArrayList<>();
        List<Long> paramsFieldRelationIds = new ArrayList<>();
        for (String fieldInfo : fieldInfos) {
            if (StringUtils.isNotEmpty(fieldInfo)) {
                String[] split = fieldInfo.split("=");
                if ("1".equals(split[1])) {
                    interfaceParamsFieldRelationIds.add(Long.parseLong(split[0]));
                } else {
                    paramsFieldRelationIds.add(Long.parseLong(split[0]));
                }
            }
        }
        if (bffParamReq.getInterfaceParamsFieldRelationId() == null) {
            this.interfaceParamsFieldRelationService.saveDubboParam(bffParamReq, interfaceParamsFieldRelationIds, paramsFieldRelationIds);
        } else {
            this.paramsFieldRelationService.saveDubboParam(bffParamReq, interfaceParamsFieldRelationIds, paramsFieldRelationIds);
        }
        return AjaxResult.success();
    }

    /**
     * 保存bff接口参数
     * @param bffParamReq
     * @return
     */
    @PostMapping("/saveBffParam")
    @ResponseBody
    public AjaxResult saveBffParam(BffParamReq bffParamReq) {
        String[] fieldInfos = bffParamReq.getFieldInfo().split(",");
        List<Long> interfaceParamsFieldRelationIds = new ArrayList<>();
        List<Long> paramsFieldRelationIds = new ArrayList<>();
        for (String fieldInfo : fieldInfos) {
            if (StringUtils.isNotEmpty(fieldInfo)) {
                String[] split = fieldInfo.split("=");
                if ("1".equals(split[1])) {
                    interfaceParamsFieldRelationIds.add(Long.parseLong(split[0]));
                } else {
                    paramsFieldRelationIds.add(Long.parseLong(split[0]));
                }
            }
        }
        if (bffParamReq.getInterfaceParamsFieldRelationId() == null) {
            this.interfaceParamsFieldRelationService.saveBffParam(bffParamReq, interfaceParamsFieldRelationIds, paramsFieldRelationIds);
        } else {
            this.paramsFieldRelationService.saveBffParam(bffParamReq, interfaceParamsFieldRelationIds, paramsFieldRelationIds);
        }
        return AjaxResult.success();
    }

    /**
     * bff接口 字段参数选择页面
     * @param interfaceId 接口id
     * @param isInParam 1 入参 2 出参
     * @param mmap mmap
     * @return
     */
    @GetMapping("bff_params_field_choose/{interfaceId}/{isInParam}/{interfaceParamsFieldRelationId}")
    public String bff_params_field_choose(@PathVariable("interfaceId") Long interfaceId,
                                   @PathVariable("isInParam") String isInParam,
                                   @PathVariable("interfaceParamsFieldRelationId") Long interfaceParamsFieldRelationId,
                                   ModelMap mmap) {
        mmap.put("interfaceId", interfaceId);
        mmap.put("isInParam", isInParam);
        mmap.put("interfaceParamsFieldRelationId", interfaceParamsFieldRelationId);

        Set<Long> vuIds = new HashSet<>();
        List<Long> groupIds = new ArrayList<>();
        Set<Long> detailVuIds = new HashSet<>();
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
        if ("Y".equals(interfaceInfo.getIsBranch())) {
            ProcessBranch processBranch = new ProcessBranch();
            processBranch.setInterfaceId(interfaceId);
            List<ProcessBranch> processBranches = this.processBranchService.selectProcessBranchList(processBranch);
            if (CollectionUtil.isNotEmpty(processBranches)) {
                for (ProcessBranch branch : processBranches) {
                    if ("1".equals(branch.getType())) {
                        vuIds.add(branch.getEntityId());
                    } else if ("4".equals(branch.getType())) {
                        groupIds.add(branch.getEntityId());
                    }
                }
            }

            VirtualUsageGroupDetail virtualUsageGroupDetail = new VirtualUsageGroupDetail();
            virtualUsageGroupDetail.setInterfaceId(interfaceId);
            List<VirtualUsageGroupDetail> virtualUsageGroupDetailList = this.virtualUsageGroupDetailService.selectVirtualUsageGroupDetailList(virtualUsageGroupDetail);
            if (CollectionUtil.isNotEmpty(virtualUsageGroupDetailList)) {
                detailVuIds = virtualUsageGroupDetailList.stream().map(VirtualUsageGroupDetail::getVirtualUsageId).collect(Collectors.toSet());
            }
        }
        VirtualUsage virtualUsage = new VirtualUsage();
        virtualUsage.setRelationInterfaceId(interfaceId);
        List<VirtualUsage> virtualUsageList = this.virtualUsageService.selectVirtualUsages(virtualUsage);
        if (CollectionUtil.isNotEmpty(virtualUsageList) && "Y".equals(interfaceInfo.getIsBranch())) {
            List<VirtualUsage> excludes = new ArrayList<>();
            Iterator<VirtualUsage> iterator = virtualUsageList.iterator();
            while (iterator.hasNext()) {
                VirtualUsage next = iterator.next();
                if (!vuIds.contains(next.getId())) {
                    excludes.add(next);
                    iterator.remove();
                }
            }
            // 将不在分支下的虚拟用况和不在组里的虚拟用况加入进去
            if (excludes.size() > 0) {
                for (VirtualUsage exclude : excludes) {
                    if (!detailVuIds.contains(exclude.getId())) {
                        virtualUsageList.add(exclude);
                    }
                }
            }
        }
        ListInterfaceFieldParamReq listInterfaceFieldParamReq = new ListInterfaceFieldParamReq();
        listInterfaceFieldParamReq.setType("2");
        listInterfaceFieldParamReq.setInterfaceId(interfaceId);
        listInterfaceFieldParamReq.setIsInParam(isInParam);
        listInterfaceFieldParamReq.setInterfaceParamsFieldRelationId(interfaceParamsFieldRelationId);
        List<InterfaceParam> listFieldParam = this.interfaceInfoService.listInterfaceParamsField(listInterfaceFieldParamReq);

        if (CollectionUtil.isNotEmpty(virtualUsageList)) {
            virtualUsageList.forEach(o -> {
                o.setVirtualUsageType("3");
            });
        }
        VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
        virtualUsageGroup.setInterfaceId(interfaceId);
        if (groupIds.size() > 0) {
            virtualUsageGroup.setIds(groupIds);
        }
        List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
        if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
            virtualUsageGroups.forEach( o -> {
                VirtualUsage virtualUsage1 = new VirtualUsage();
                virtualUsage1.setSlaveInterfaceName(o.getGroupName());
                virtualUsage1.setId(o.getId());
                virtualUsage1.setVirtualUsageType("5");
                virtualUsage1.setIsMaster(o.getIsMaster());
                virtualUsageList.add(virtualUsage1);
            });
        }
        for (VirtualUsage usage : virtualUsageList) {
            if ("Y".equals(usage.getIsMaster())) {
                usage.setSlaveInterfaceName(usage.getSlaveInterfaceName()+" （主）");
            }
        }
        mmap.put("listFieldParam", listFieldParam);
        mmap.put("virtualUsageList", virtualUsageList);
        return prefix + "/bff_params_field_choose";
    }

    /**
     * dubbo接口 字段参数选择页面
     * @param interfaceId 接口id
     * @param isInParam 1 入参 2 出参
     * @param mmap mmap
     * @return
     */
    @GetMapping("dubbo_params_field_choose/{interfaceId}/{isInParam}/{interfaceParamsFieldRelationId}")
    public String dubbo_params_field_choose(@PathVariable("interfaceId") Long interfaceId,
                                          @PathVariable("isInParam") String isInParam,
                                          @PathVariable("interfaceParamsFieldRelationId") Long interfaceParamsFieldRelationId,
                                          ModelMap mmap) {
        mmap.put("interfaceId", interfaceId);
        mmap.put("isInParam", isInParam);
        mmap.put("interfaceParamsFieldRelationId", interfaceParamsFieldRelationId);

        Set<Long> vuIds = new HashSet<>();
        List<Long> groupIds = new ArrayList<>();
        Set<Long> detailVuIds = new HashSet<>();
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
        if ("Y".equals(interfaceInfo.getIsBranch())) {
            ProcessBranch processBranch = new ProcessBranch();
            processBranch.setInterfaceId(interfaceId);
            List<ProcessBranch> processBranches = this.processBranchService.selectProcessBranchList(processBranch);
            if (CollectionUtil.isNotEmpty(processBranches)) {
                for (ProcessBranch branch : processBranches) {
                    if ("1".equals(branch.getType())) {
                        vuIds.add(branch.getEntityId());
                    } else if ("4".equals(branch.getType())) {
                        groupIds.add(branch.getEntityId());
                    }
                }
            }

            VirtualUsageGroupDetail virtualUsageGroupDetail = new VirtualUsageGroupDetail();
            virtualUsageGroupDetail.setInterfaceId(interfaceId);
            List<VirtualUsageGroupDetail> virtualUsageGroupDetailList = this.virtualUsageGroupDetailService.selectVirtualUsageGroupDetailList(virtualUsageGroupDetail);
            if (CollectionUtil.isNotEmpty(virtualUsageGroupDetailList)) {
                detailVuIds = virtualUsageGroupDetailList.stream().map(VirtualUsageGroupDetail::getVirtualUsageId).collect(Collectors.toSet());
            }
        }
        VirtualUsage virtualUsage = new VirtualUsage();
        virtualUsage.setRelationInterfaceId(interfaceId);
        List<VirtualUsage> virtualUsageList = this.virtualUsageService.selectVirtualUsages(virtualUsage);
        if (CollectionUtil.isNotEmpty(virtualUsageList) && "Y".equals(interfaceInfo.getIsBranch())) {
            List<VirtualUsage> excludes = new ArrayList<>();
            Iterator<VirtualUsage> iterator = virtualUsageList.iterator();
            while (iterator.hasNext()) {
                VirtualUsage next = iterator.next();
                if (!vuIds.contains(next.getId())) {
                    excludes.add(next);
                    iterator.remove();
                }
            }
            // 将不在分支下的虚拟用况和不在组里的虚拟用况加入进去
            if (excludes.size() > 0) {
                for (VirtualUsage exclude : excludes) {
                    if (!detailVuIds.contains(exclude.getId())) {
                        virtualUsageList.add(exclude);
                    }
                }
            }
        }
        ListInterfaceFieldParamReq listInterfaceFieldParamReq = new ListInterfaceFieldParamReq();
        listInterfaceFieldParamReq.setType("4");
        listInterfaceFieldParamReq.setInterfaceId(interfaceId);
        listInterfaceFieldParamReq.setIsInParam(isInParam);
        listInterfaceFieldParamReq.setInterfaceParamsFieldRelationId(interfaceParamsFieldRelationId);
        List<InterfaceParam> listFieldParam = this.interfaceInfoService.listInterfaceParamsField(listInterfaceFieldParamReq);
        if (CollectionUtil.isNotEmpty(virtualUsageList)) {
            virtualUsageList.forEach(o -> {
                o.setVirtualUsageType("3");
            });
        }

        if (groupIds.size() > 0) {
            VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
            virtualUsageGroup.setInterfaceId(interfaceId);
            virtualUsageGroup.setIds(groupIds);
            List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
            if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
                virtualUsageGroups.forEach( o -> {
                    VirtualUsage virtualUsage1 = new VirtualUsage();
                    virtualUsage1.setSlaveInterfaceName(o.getGroupName());
                    virtualUsage1.setId(o.getId());
                    virtualUsage1.setVirtualUsageType("5");
                    virtualUsage1.setIsMaster(o.getIsMaster());
                    virtualUsageList.add(virtualUsage1);
                });
            }
        }

        for (VirtualUsage usage : virtualUsageList) {
            if ("Y".equals(usage.getIsMaster())) {
                usage.setSlaveInterfaceName(usage.getSlaveInterfaceName()+" （主）");
            }
        }
        mmap.put("listFieldParam", listFieldParam);
        mmap.put("virtualUsageList", virtualUsageList);
        return prefix + "/dubbo_params_field_choose";
    }

    /**
     * 更新bff字段状态
     * @param interfaceParamsFieldRelation
     * @return
     */
    @PostMapping("/updateBffFieldStatus")
    @ResponseBody
    public AjaxResult updateBffFieldStatus(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        return success();
    }

    /**
     * 更新虚拟用况接口排序
     * @param virtualUsages
     * @return
     */
    @PostMapping("/updateInterfaceSort")
    @ResponseBody
    public AjaxResult updateInterfaceSort(@RequestBody List<VirtualUsage> virtualUsages) {
        this.virtualUsageService.updateInterfaceSort(virtualUsages);
        return success();
    }

    /**
     * 删除接口 字段(数据集)数据
     * @param id
     * @return
     */
    @GetMapping("removeField/{id}")
    @ResponseBody
    public AjaxResult removeField(@PathVariable("id") Long id) {
        InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(id);
        if (interfaceParamsFieldRelation != null) {
            if (interfaceParamsFieldRelation.getType().equals("1") || interfaceParamsFieldRelation.getType().equals("4")) {
                // method dubbo
                List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(Collections.singletonList(id), "1");
                if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                    return AjaxResult.warn("该字段与虚拟用况有关联，请解除关联");
                }
            } else if (interfaceParamsFieldRelation.getType().equals("2")) {
                // bff
            } else if (interfaceParamsFieldRelation.getType().equals("3") || interfaceParamsFieldRelation.getType().equals("5")) {
                // 虚拟用况、虚拟用况组
                if (interfaceParamsFieldRelation.getObjectType().equals("1")) {
                    // 1.查询interfaceParamsFieldRelation表
                    List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(Collections.singletonList(id), "1");
                    if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                        return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                    }
                    // 2.查询paramsFieldRelation表
                    List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(Collections.singletonList(id), "1");
                    if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
                        return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                    }
                } else {
                    ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
                    paramsFieldRelation.setInterfaceDataListId(id);
                    List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationService.selectParamsFieldRelationList(paramsFieldRelation);
                    if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
                        List<Long> collect = paramsFieldRelationList.stream().map(ParamsFieldRelation::getId).collect(Collectors.toList());
                        // 1.查询interfaceParamsFieldRelation表
                        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(collect, "2");
                        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                            return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                        }
                        // 2.查询paramsFieldRelation表
                        List<ParamsFieldRelation> paramsFieldRelationList2 = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(collect, "2");
                        if (CollectionUtil.isNotEmpty(paramsFieldRelationList2)) {
                            return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                        }
                    }
                }
            } else {
                return error("参数非法");
            }
        }
        this.interfaceParamsFieldRelationService.removeField(interfaceParamsFieldRelation);
        return success();
    }

    /**
     * 删除接口 数据集字段数据
     * @param id
     * @return
     */
    @GetMapping("removeParamsField/{id}")
    @ResponseBody
    public AjaxResult removeParamsField(@PathVariable("id") Long id) {
        ParamsFieldRelation paramsFieldRelation = this.paramsFieldRelationService.selectParamsFieldRelationById(id);
        InterfaceParamsFieldRelation interfaceParamsFieldRelation = null;
        if (paramsFieldRelation != null) {
            interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(paramsFieldRelation.getInterfaceDataListId());
            if (interfaceParamsFieldRelation != null) {
                if (interfaceParamsFieldRelation.getType().equals("1") || interfaceParamsFieldRelation.getType().equals("4")) {
                    // method dubbo
                    List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(Collections.singletonList(id), "2");
                    if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
                        return AjaxResult.warn("该字段与虚拟用况有关联，请解除关联");
                    }
                } else if (interfaceParamsFieldRelation.getType().equals("2")) {
                    // bff
                } else {
                    // 虚拟用况
                    // 1.查询interfaceParamsFieldRelation表
                    List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(Collections.singletonList(id), "2");
                    if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                        return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                    }
                    // 2.查询paramsFieldRelation表
                    List<ParamsFieldRelation> paramsFieldRelationList2 = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(Collections.singletonList(id), "2");
                    if (CollectionUtil.isNotEmpty(paramsFieldRelationList2)) {
                        return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                    }
                }
            }
        }
        this.paramsFieldRelationService.removeParamsField(id, interfaceParamsFieldRelation);
        return success();
    }

    /**
     * 删除虚拟用况
     * @param id
     * @return
     */
    @GetMapping("removeVirtualUsage/{id}")
    @ResponseBody
    public AjaxResult removeVirtualUsage(@PathVariable("id") Long id) {
        InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
        interfaceParamsFieldRelation.setInterfaceId(id);
        interfaceParamsFieldRelation.setType("3");
        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelations = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation);
        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelations)) {
            return AjaxResult.warn("虚拟用况下有字段，请解除关联");
        }

        ProcessBranch processBranch = new ProcessBranch();
        processBranch.setEntityId(id);
        processBranch.setType("1");
        List<ProcessBranch> processBranches = this.processBranchService.selectProcessBranchList(processBranch);
        if (CollectionUtil.isNotEmpty(processBranches)) {
            return AjaxResult.warn("虚拟用况被分支引用，请解除关联");
        }
        this.virtualUsageService.deleteVirtualUsageById(id);
        return success();
    }

    /**
     * 更新接口状态
     * @param interfaceInfo
     * @return
     */
    @PostMapping("/updateInterfaceStatus")
    @ResponseBody
    public AjaxResult updateInterfaceStatus(InterfaceInfo interfaceInfo) {
        this.interfaceInfoService.updateInterfaceInfo(interfaceInfo);
        return success();
    }

    @GetMapping("setOrder/{interfaceId}/{id}")
    public String setOrder(@PathVariable("interfaceId") Long interfaceId, @PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("interfaceId", interfaceId);
        mmap.put("id", id);
        FileInf fileInf = this.fileInfoService.selectFileInfoById(id);
        mmap.put("fileInf", fileInf);
        return "page/page/new/setOrder";
    }

    @GetMapping("add_bff_img/{interfaceId}")
    public String add_bff_img(@PathVariable("interfaceId") Long interfaceId,
                              @RequestParam(value = "parentId",required = false) Long parentId,
                              @RequestParam(value = "type",required = false,defaultValue = "0") Long type,
                              ModelMap mmap) {
        mmap.put("interfaceId", interfaceId);
        mmap.put("parentId", parentId);
        mmap.put("type", type);
        return prefix + "/add_bff_img";
    }

    /**
     * 添加bff 图片
     * @param bffImgReq
     * @return
     */
    @PostMapping("/addBffImg")
    @ResponseBody
    public AjaxResult addBffImg(@RequestBody BffImgReq bffImgReq) {
        this.interfaceInfoService.addBffImg(bffImgReq);
        return success();
    }

    /**
     * 更新method操作
     * @param interfaceParamsFieldRelation
     * @return
     */
    @PostMapping("/updateMethodOperate")
    @ResponseBody
    public AjaxResult updateMethodOperate(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        return success();
    }

    /**
     * 更新节点类型
     * @param interfaceParamsFieldRelation
     * @return
     */
    @PostMapping("/updateFieldNodeType")
    @ResponseBody
    public AjaxResult updateFieldNodeType(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        return success();
    }

    /**
     * 更新节点 是否是树形
     * @param interfaceParamsFieldRelation
     * @return
     */
    @PostMapping("/updateFieldIsTree")
    @ResponseBody
    public AjaxResult updateFieldIsTree(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        return success();
    }

    @GetMapping("/fieldDesign")
    public String fieldDesign(Long id, Integer type, ModelMap modelMap) {
        String isRequired;
        String fieldDescription;
        String designContent;
        String isUpdate;
        boolean isRequiredFlag = false;
        String orderType;
        String isMethod = "N";
        String dictCategory, dictType, dictValue;

        if (type == 1) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(id);
            modelMap.put("fbType", interfaceParamsFieldRelation.getType());
            modelMap.put("aliasZhName", interfaceParamsFieldRelation.getAliasZhName());
            modelMap.put("aliasName", interfaceParamsFieldRelation.getAliasName());
            isRequired = interfaceParamsFieldRelation.getIsRequired();
            fieldDescription = interfaceParamsFieldRelation.getFieldDescription();
            designContent = interfaceParamsFieldRelation.getDesignContent();
            isUpdate = interfaceParamsFieldRelation.getIsUpdate();
            orderType = interfaceParamsFieldRelation.getOrderType();
            dictCategory = interfaceParamsFieldRelation.getDictCategory();
            dictType = interfaceParamsFieldRelation.getDictType();
            dictValue = interfaceParamsFieldRelation.getDictValue();
            FieldInfo fieldInfo = selectFieldInfo(interfaceParamsFieldRelation.getObjectId(), modelMap);
            if (interfaceParamsFieldRelation.getType().equals("1")) {
                isMethod = "Y";
                if (!"Y".equals(fieldInfo.getIsRequired())) {
                    isRequiredFlag = true;
                }
            } else {
                // 查询父级
                if ("1".equals(interfaceParamsFieldRelation.getDataRelationType()) && interfaceParamsFieldRelation.getDataRelationId() != null) {
                    InterfaceParamsFieldRelation parent = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(interfaceParamsFieldRelation.getDataRelationId());
                    if (!"Y".equals(parent.getIsRequired())) {
                        isRequiredFlag = true;
                    }
                } else if ("2".equals(interfaceParamsFieldRelation.getDataRelationType()) && interfaceParamsFieldRelation.getDataRelationId() != null) {
                    ParamsFieldRelation parent = this.paramsFieldRelationService.selectParamsFieldRelationById(interfaceParamsFieldRelation.getDataRelationId());
                    if (!"Y".equals(parent.getIsRequired())) {
                        isRequiredFlag = true;
                    }
                }
            }
        } else {
            ParamsFieldRelation paramsFieldRelation = this.paramsFieldRelationService.selectParamsFieldRelationById(id);
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(paramsFieldRelation.getInterfaceDataListId());
            modelMap.put("fbType", interfaceParamsFieldRelation.getType());
            modelMap.put("aliasZhName", paramsFieldRelation.getAliasZhName());
            modelMap.put("aliasName", paramsFieldRelation.getAliasName());
            isRequired = paramsFieldRelation.getIsRequired();
            fieldDescription = paramsFieldRelation.getFieldDescription();
            designContent = paramsFieldRelation.getDesignContent();
            isUpdate = paramsFieldRelation.getIsUpdate();
            orderType = paramsFieldRelation.getOrderType();

            dictCategory = paramsFieldRelation.getDictCategory();
            dictType = paramsFieldRelation.getDictType();
            dictValue = paramsFieldRelation.getDictValue();
            FieldInfo fieldInfo = selectFieldInfo(paramsFieldRelation.getFieldId(), modelMap);
            if (interfaceParamsFieldRelation.getType().equals("1")) {
                isMethod = "Y";
                if (fieldInfo.getIsRequired().equals("N")) {
                    isRequiredFlag = true;
                }
            } else {
                // 查询父级
                if ("1".equals(paramsFieldRelation.getDataRelationType()) && paramsFieldRelation.getDataRelationId() != null) {
                    InterfaceParamsFieldRelation parent = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(paramsFieldRelation.getDataRelationId());
                    if (!"Y".equals(parent.getIsRequired())) {
                        isRequiredFlag = true;
                    }
                } else if ("2".equals(paramsFieldRelation.getDataRelationType()) && paramsFieldRelation.getDataRelationId() != null) {
                    ParamsFieldRelation parent = this.paramsFieldRelationService.selectParamsFieldRelationById(paramsFieldRelation.getDataRelationId());
                    if (!"Y".equals(parent.getIsRequired())) {
                        isRequiredFlag = true;
                    }
                }
            }

        }
        modelMap.put("isRequiredFlag", isRequiredFlag);
        modelMap.put("id", id);
        modelMap.put("type", type);
        modelMap.put("isRequired", StringUtils.isEmpty(isRequired) ? "Y" : isRequired);
        modelMap.put("fieldDescription", fieldDescription == null ? "" : fieldDescription);
        modelMap.put("designContent", designContent == null ? "" : designContent);
        modelMap.put("isUpdate", isUpdate);
        modelMap.put("orderType", orderType == null ? "" : orderType);
        modelMap.put("isMethod", isMethod);

        Boolean otherFlag = (Boolean) modelMap.get("otherFlag");
        List<SysDictData> dictCategoryList = new ArrayList<>();
        List<SysDictData> dictValueList = new ArrayList<>();
        List<SysDictType> dictTypeList = new ArrayList<>();
        if (otherFlag != null) {
                List<SysDictData> dataDictionary = this.sysDictTypeService.selectDictDataByType("dataDictionary");
                for (SysDictData sysDictData : dataDictionary) {
                    //if (!"1".equals(sysDictData.getDictValue()) && !"2".equals(sysDictData.getDictValue())) {
                    if (!"1".equals(sysDictData.getDictValue())) {
                        dictCategoryList.add(sysDictData);
                    }
                }
                if (StringUtils.isNotEmpty(dictCategory)) {
                    SysDictType dictType1 = new SysDictType();
                    dictType1.setCategory(dictCategory);
                    dictTypeList = this.sysDictTypeService.selectDictTypeList(dictType1);
                }
                if (StringUtils.isNotEmpty(dictType)) {
                    dictValueList = this.sysDictTypeService.selectDictDataByType(dictType);
                }

        }
        modelMap.put("dictCategoryList", dictCategoryList);
        modelMap.put("dictValueList", dictValueList);
        modelMap.put("dictTypeList", dictTypeList);
        modelMap.put("dictCategory", StringUtils.isNotEmpty(dictCategory) ? dictCategory : "");
        modelMap.put("dictValue",  StringUtils.isNotEmpty(dictValue) ? dictValue : "");
        modelMap.put("dictType",  StringUtils.isNotEmpty(dictType) ? dictType : "");
        return prefix + "/fieldDesign";
    }

    private FieldInfo selectFieldInfo(Long fieldId, ModelMap modelMap) {
        List<FieldInfo> fieldInfoList = this.tableInfoService.selectFieldInfoByFieldId(Arrays.asList(fieldId));
        FieldInfo fieldInfo = fieldInfoList.get(0);
        boolean pkFlag = false;
        boolean fkFlag = false;
        boolean timeFlag = false;
        boolean enumFlag = false;
        boolean otherFlag = false;
        if (fieldInfo.getFieldType().equals("1")) {
            pkFlag = true;
        } else if (fieldInfo.getFieldType().equals("2")) {
            fkFlag = true;
        } else if (fieldInfo.getIsFieldEnum().equals("Y")) {
            enumFlag = true;
            List<SysDictData> sysDictDatas = new ArrayList<>();
            if (fieldInfo.getDictId() != null) {
                SysDictType sysDictType = this.sysDictTypeService.selectDictTypeById(fieldInfo.getDictId());
                if (sysDictType != null) {
                    SysDictData dictData = new SysDictData();
                    dictData.setDictType(sysDictType.getDictType());
                    sysDictDatas = this.sysDictDataService.selectDictDataList(dictData);
                }
            }
            modelMap.put("sysDictDatas", sysDictDatas);
        } else if (fieldInfo.getFieldDataType().equals("3")) {
            timeFlag = true;
        } else {
            otherFlag = true;
        }
        modelMap.put("pkFlag", pkFlag);
        modelMap.put("fkFlag", fkFlag);
        modelMap.put("timeFlag", timeFlag);
        modelMap.put("enumFlag", enumFlag);
        modelMap.put("otherFlag", otherFlag);
        return fieldInfo;
    }

    @PostMapping("/updateFieldDesign")
    @ResponseBody
    public AjaxResult updateFieldDesign (InterfaceParamsFieldRelation fieldRelation) {
        String aliasName = fieldRelation.getAliasName();
        String aliasZhName = fieldRelation.getAliasZhName();
        Long id = fieldRelation.getId();
        String type = fieldRelation.getType();
        String designContent = fieldRelation.getDesignContent();
        String fieldDescription = fieldRelation.getFieldDescription();
        if (StringUtils.isNotEmpty(aliasZhName) || StringUtils.isNotEmpty(aliasName)) {
            if (type.equals("1")) {
                InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
                interfaceParamsFieldRelation.setId(id);
                interfaceParamsFieldRelation.setAliasName(aliasName);
                interfaceParamsFieldRelation.setAliasZhName(aliasZhName);
                this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
            } else {
                ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
                paramsFieldRelation.setId(id);
                paramsFieldRelation.setAliasName(aliasName);
                paramsFieldRelation.setAliasZhName(aliasZhName);
                this.paramsFieldRelationService.updateParamsFieldRelation(paramsFieldRelation);
            }
        }
        if("-1".equals(designContent)) {
            designContent = null;
        }
        if (StringUtils.isNotEmpty(fieldDescription) || StringUtils.isNotEmpty(designContent)) {
            fieldRelation.setIsUpdate("N");
            this.interfaceParamsFieldRelationService.updateFieldDesign(fieldRelation);
        }
        return success();
    }

    @Resource
    private IErrorCodeCategoryService errorCodeCategoryService;

    @GetMapping("/fieldDesign2")
    public String fieldDesign2(Long id, Integer type, ModelMap modelMap) {
        boolean isMethod = false, isBff = false, isTree = false, isOther = true;
        InterfaceParamsFieldRelation interfaceParamsFieldRelation = null;
        if (type == 1) {
            interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(id);
            //modelMap.put("orderType", interfaceParamsFieldRelation.getOrderType() == null ? "" : interfaceParamsFieldRelation.getOrderType());
        } else {
            ParamsFieldRelation paramsFieldRelation = this.paramsFieldRelationService.selectParamsFieldRelationById(id);
            interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(paramsFieldRelation.getInterfaceDataListId());
            interfaceParamsFieldRelation.setAliasName(paramsFieldRelation.getAliasName());
            interfaceParamsFieldRelation.setAliasZhName(paramsFieldRelation.getAliasZhName());
            interfaceParamsFieldRelation.setTreeModel(paramsFieldRelation.getTreeModel());
            interfaceParamsFieldRelation.setOtherModel(paramsFieldRelation.getOtherModel());
            interfaceParamsFieldRelation.setOrderType(paramsFieldRelation.getOrderType());
            interfaceParamsFieldRelation.setFieldDescription(paramsFieldRelation.getFieldDescription());
            interfaceParamsFieldRelation.setIsAllowEmpty(paramsFieldRelation.getIsAllowEmpty());
            interfaceParamsFieldRelation.setObjectType("1");
            interfaceParamsFieldRelation.setErrorCodeCategoryId(paramsFieldRelation.getErrorCodeCategoryId());
            interfaceParamsFieldRelation.setErrorCode(paramsFieldRelation.getErrorCode());
            //modelMap.put("orderType", paramsFieldRelation.getOrderType() == null ? "" : paramsFieldRelation.getOrderType());
        }
        if (interfaceParamsFieldRelation.getObjectType().equals("1")) {
            Long interfaceId = interfaceParamsFieldRelation.getInterfaceId();
            if ("1".equals(interfaceParamsFieldRelation.getType())) {
                isMethod = true;
            } else if ("2".equals(interfaceParamsFieldRelation.getType()) || "4".equals(interfaceParamsFieldRelation.getType())) {
                isBff = true;
            } else if ("3".equals(interfaceParamsFieldRelation.getType())) {
                VirtualUsage virtualUsage = this.virtualUsageService.selectVirtualUsageById(interfaceId);
                interfaceId = virtualUsage.getRelationInterfaceId();
            }
            InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
            if ("Y".equals(interfaceInfo.getIsTree())) {
                isTree = true;
            }
        } else {
            isOther = false;
        }

        if ("1".equals(interfaceParamsFieldRelation.getIsAllowEmpty()) && interfaceParamsFieldRelation.getErrorCodeCategoryId() != null && interfaceParamsFieldRelation.getErrorCodeCategoryId() != 0L) {
            ErrorCodeCategory errorCodeCategory = errorCodeCategoryService.selectErrorCodeCategoryByErrorCodeCategoryId(interfaceParamsFieldRelation.getErrorCodeCategoryId());
            modelMap.put("errorCodeCategoryName", errorCodeCategory.getErrorCodeCategoryName());
        }
        modelMap.put("id", id);
        modelMap.put("type", type);
        modelMap.put("isMethod", isMethod);
        modelMap.put("isBff", isBff);
        modelMap.put("isTree", isTree);
        modelMap.put("isOther", isOther);
        modelMap.put("interfaceParamsFieldRelation", interfaceParamsFieldRelation);
        return prefix + "/fieldDesign2";
    }

    @PostMapping("/updateFieldDesign2")
    @ResponseBody
//    public AjaxResult updateFieldDesign2(Long id, Integer type, String orderType, String fieldDescription) {

//        if (type == 1) {
//            InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(id);
//            this.interfaceParamsFieldRelationService.updateFieldDesign(id, type, fieldDescription, interfaceParamsFieldRelation.getDesignContent(), orderType, interfaceParamsFieldRelation.getIsRequired(), "Y");
//        } else {
//            ParamsFieldRelation paramsFieldRelation = this.paramsFieldRelationService.selectParamsFieldRelationById(id);
//            this.interfaceParamsFieldRelationService.updateFieldDesign(id, type, paramsFieldRelation.getFieldDescription(), paramsFieldRelation.getDesignContent(), orderType, paramsFieldRelation.getIsRequired(), "Y");
//        }
    public AjaxResult updateFieldDesign2(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        if (!"1".equals(interfaceParamsFieldRelation.getIsAllowEmpty())) {
            interfaceParamsFieldRelation.setErrorCode("");
            interfaceParamsFieldRelation.setErrorCodeCategoryId(0L);
        }
        if (interfaceParamsFieldRelation.getType().equals("1")) {
            interfaceParamsFieldRelation.setType(null);
            this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        } else {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            BeanUtils.copyProperties(interfaceParamsFieldRelation, paramsFieldRelation);
            this.paramsFieldRelationService.updateParamsFieldRelation(paramsFieldRelation);
        }
        return success();
    }

    @PostMapping("/resetFieldDesign2")
    @ResponseBody
   public AjaxResult resetFieldDesign2(InterfaceParamsFieldRelation interfaceParamsFieldRelation) {
        if (interfaceParamsFieldRelation.getType().equals("1")) {
            interfaceParamsFieldRelation.setType(null);
            interfaceParamsFieldRelation.setAliasName("");
            interfaceParamsFieldRelation.setAliasZhName("");
            interfaceParamsFieldRelation.setTreeModel("");
            interfaceParamsFieldRelation.setOtherModel("");
            interfaceParamsFieldRelation.setOrderType("");
            interfaceParamsFieldRelation.setFieldDescription("");
            interfaceParamsFieldRelation.setIsAllowEmpty("");
            this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        } else {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            paramsFieldRelation.setId(interfaceParamsFieldRelation.getId());
            paramsFieldRelation.setAliasName("");
            paramsFieldRelation.setAliasZhName("");
            paramsFieldRelation.setTreeModel("");
            paramsFieldRelation.setOtherModel("");
            paramsFieldRelation.setOrderType("");
            paramsFieldRelation.setFieldDescription("");
            paramsFieldRelation.setIsAllowEmpty("");
            this.paramsFieldRelationService.updateParamsFieldRelation(paramsFieldRelation);
        }
        return success();
    }

    @PostMapping("/resetFieldDesign")
    @ResponseBody
    public AjaxResult resetFieldDesign(Long id, Integer type) {
        if (type==1) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
            interfaceParamsFieldRelation.setId(id);
            interfaceParamsFieldRelation.setAliasName("");
            interfaceParamsFieldRelation.setAliasZhName("");
            this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        } else {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            paramsFieldRelation.setId(id);
            paramsFieldRelation.setAliasName("");
            paramsFieldRelation.setAliasZhName("");
            this.paramsFieldRelationService.updateParamsFieldRelation(paramsFieldRelation);
        }
        InterfaceParamsFieldRelation relation = new InterfaceParamsFieldRelation();
        relation.setId(id);
        relation.setType(type + "");
        relation.setFieldDescription("");
        relation.setDesignContent("");
        relation.setOrderType("");
        relation.setIsRequired(null);
        relation.setIsUpdate("Y");
        relation.setDictCategory("");
        relation.setDictValue("");
        relation.setDictType("");
        this.interfaceParamsFieldRelationService.updateFieldDesign(relation);
        return success();
    }

    @PostMapping("/updateIsRequired")
    @ResponseBody
    public AjaxResult resetFieldDesign(Long id, Integer type, String isRequired) {
        InterfaceParamsFieldRelation relation = new InterfaceParamsFieldRelation();
        relation.setId(id);
        relation.setType(type + "");
        relation.setFieldDescription(null);
        relation.setDesignContent(null);
        relation.setOrderType(null);
        relation.setIsRequired(isRequired);
        relation.setIsUpdate(null);
        this.interfaceParamsFieldRelationService.updateFieldDesign(relation);
        return success();
    }

    @GetMapping("/setAliasName")
    public String setAliasName(Long id, Integer type, ModelMap modelMap) {
        modelMap.put("id", id);
        modelMap.put("type", type);
        InterfaceParamsFieldRelation interfaceParamsFieldRelation = null;
        if (type == 1) {
            interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(id);
            modelMap.put("aliasName", StringUtils.isNotEmpty(interfaceParamsFieldRelation.getAliasName()) ? interfaceParamsFieldRelation.getAliasName() : "");
            modelMap.put("designContent", StringUtils.isNotEmpty(interfaceParamsFieldRelation.getDesignContent()) ? interfaceParamsFieldRelation.getDesignContent() : "");

        } else {
            ParamsFieldRelation paramsFieldRelation = this.paramsFieldRelationService.selectParamsFieldRelationById(id);
            interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
            modelMap.put("aliasName", StringUtils.isNotEmpty(paramsFieldRelation.getAliasName()) ? paramsFieldRelation.getAliasName() : "");
            modelMap.put("designContent", StringUtils.isNotEmpty(paramsFieldRelation.getDesignContent()) ? paramsFieldRelation.getDesignContent() : "");
            interfaceParamsFieldRelation.setDesignContent(paramsFieldRelation.getDesignContent());
        }
        modelMap.put("interfaceParamsFieldRelation", interfaceParamsFieldRelation);
        return prefix + "/setAliasName";
    }

    @PostMapping("/updateAliasName")
    @ResponseBody
    public AjaxResult updateAliasName(Long id, Integer type, String aliasName, String designContent) {
        if(StringUtils.isBlank(aliasName)) {
            aliasName = "";
        }
        if (type == 1) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
            interfaceParamsFieldRelation.setId(id);
            interfaceParamsFieldRelation.setAliasName(aliasName);
            interfaceParamsFieldRelation.setDesignContent(designContent);
            this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        } else {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            paramsFieldRelation.setId(id);
            paramsFieldRelation.setAliasName(aliasName);
            paramsFieldRelation.setDesignContent(designContent);
            this.paramsFieldRelationService.updateParamsFieldRelation(paramsFieldRelation);
        }
        return success();
    }

    @PostMapping("/updateConditionWay")
    @ResponseBody
    public AjaxResult updateConditionWay(Long id, Integer type, String conditionWay) {
        if (type == 1) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = new InterfaceParamsFieldRelation();
            interfaceParamsFieldRelation.setId(id);
            interfaceParamsFieldRelation.setConditionWay(conditionWay);
            this.interfaceParamsFieldRelationService.updateInterfaceParamsFieldRelation(interfaceParamsFieldRelation);
        } else {
            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
            paramsFieldRelation.setId(id);
            paramsFieldRelation.setConditionWay(conditionWay);
            this.paramsFieldRelationService.updateParamsFieldRelation(paramsFieldRelation);
        }
        return success();
    }

    /**
     * 获取接口 入参的mock数据
     * @author chenxiaoyu
     * @date 2022/3/29 下午11:26
     * @param interfaceType 1-method 2-bff 3-vm(虚拟用况) 4-dubbo
     * @param interfaceId 接口id
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @PostMapping("/inParamMockData")
    @ResponseBody
    public String inParamMockData(@RequestParam String interfaceType, @RequestParam Long interfaceId) {
        List<InterfaceParam> requestList = this.interfaceInfoService.paramList(interfaceType, interfaceId, "1");
        if ("3".equals(interfaceType)) {
            VirtualUsage virtualUsage = this.virtualUsageService.selectVirtualUsageById(interfaceId);
            interfaceId = virtualUsage.getInterfaceId();
        }
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
        if ("Y".equals(interfaceInfo.getIsPage())) {
            if (!CollectionUtil.isNotEmpty(requestList)) {
                requestList = new ArrayList<>();
            }
            InterfaceParam interfaceParam = new InterfaceParam();
            interfaceParam.setFieldEnName("pageNum");
            interfaceParam.setFieldName("当前页");
            interfaceParam.setMockData("1");
            requestList.add(interfaceParam);
            InterfaceParam interfaceParam2 = new InterfaceParam();
            interfaceParam2.setFieldEnName("pageSize");
            interfaceParam2.setFieldName("每页大小");
            interfaceParam2.setMockData("10");
            requestList.add(interfaceParam2);
        }
        if (requestList.size() == 1 && "1".equals(interfaceInfo.getInterfaceType())) {
            InterfaceParam interfaceParam = requestList.get(0);
            if (interfaceParam.getObjectType().equals("1")) {
                return interfaceParam.getFieldEnName() + "=" + interfaceParam.getMockData();
            } else {
                if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                    return interfaceParam.getFieldEnName() + "=[" + interfaceParam.getChildren().get(0).getMockData() + "]";
                } else {
                    return interfaceParam.getFieldEnName() + "=[]";
                }
            }
        } else {
            Map<String, Object> result = new HashMap<>();
            for (InterfaceParam interfaceParam : requestList) {
                if (interfaceParam.getObjectType().equals("1")) {
                    result.put(interfaceParam.getFieldEnName(), interfaceParam.getMockData());
                } else {
                    if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                        if (interfaceParam.getChildren().size() == 1) {
                            result.put(interfaceParam.getFieldEnName(), Arrays.asList(interfaceParam.getChildren().get(0).getMockData()));
                        } else {
                            List<Map<String, Object>> datas = new ArrayList<>();
                            Map<String, Object> data = new HashMap<>();
                            for (InterfaceParam child : interfaceParam.getChildren()) {
                                data.put(child.getFieldEnName(), child.getMockData());
                            }
                            datas.add(data);
                            result.put(interfaceParam.getFieldEnName(), datas);
                        }
                    } else {
                        result.put(interfaceParam.getFieldEnName(), new ArrayList<>());
                    }
                }
            }
            return JSONObject.toJSONString(result);
        }
    }

    @Resource
    private VirtualUsageParamSourceMapper virtualUsageParamSourceMapper;

    @Resource
    private ParamsFieldRelationMapper paramsFieldRelationMapper;

    @GetMapping("/refreshFieldSource")
    @ResponseBody
    public AjaxResult refreshFieldSource() {
        List<InterfaceInfo> interfaceInfoList = this.interfaceInfoService.selectInterfaceInfoList(new InterfaceInfo());
        interfaceInfoList.forEach(info -> {
            if ("N".equals(info.getIsBranch()) && !"1".equals(info.getFbType())) {
                List<InterfaceParam> request;
                if ("2".equals(info.getFbType())) {
                    request = this.interfaceInfoService.paramList("2", info.getId(), "1");
                } else {
                    request = this.interfaceInfoService.paramList("4", info.getId(), "1");
                }
                for (InterfaceParam interfaceParam : request) {
                    if (interfaceParam.getDataRelationId() != null) {
                        VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
                        virtualUsageParamSource.setType(interfaceParam.getDataRelationType());
                        virtualUsageParamSource.setSourceType("1");
                        virtualUsageParamSource.setSourceobjectId(interfaceParam.getId());
                        virtualUsageParamSource.setObjectId(interfaceParam.getDataRelationId());
                        if (interfaceParam.getDataRelationType().equals("1")) {
                            InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(interfaceParam.getDataRelationId());
                            virtualUsageParamSource.setInterfaceId(interfaceParamsFieldRelation.getInterfaceId());
                        } else {
                            ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
                            paramsFieldRelation.setId(interfaceParam.getDataRelationId());
                            List<ParamsFieldRelation> paramsFieldRelationList = paramsFieldRelationMapper.selectParamsFieldRelations(paramsFieldRelation);
                            virtualUsageParamSource.setInterfaceId(paramsFieldRelationList.get(0).getInterfaceId());
                        }
                        List<VirtualUsageParamSource> virtualUsageParamSourceList = this.virtualUsageParamSourceMapper.selectVirtualUsageParamSourceList2(virtualUsageParamSource);
                        if (CollectionUtil.isEmpty(virtualUsageParamSourceList)) {
                            this.virtualUsageParamSourceMapper.insertVirtualUsageParamSource(virtualUsageParamSource);
                        }
                    }
                    if (CollectionUtil.isNotEmpty(interfaceParam.getChildren())) {
                        for (InterfaceParam child : interfaceParam.getChildren()) {
                            VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
                            virtualUsageParamSource.setType(child.getDataRelationType());
                            virtualUsageParamSource.setSourceType("2");
                            virtualUsageParamSource.setSourceobjectId(child.getId());
                            virtualUsageParamSource.setObjectId(child.getDataRelationId());
                            if (child.getDataRelationType().equals("1")) {
                                InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.
                                        selectInterfaceParamsFieldRelationById(child.getDataRelationId());
                                virtualUsageParamSource.setInterfaceId(interfaceParamsFieldRelation.getInterfaceId());
                            } else {
                                ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
                                paramsFieldRelation.setId(child.getDataRelationId());
                                List<ParamsFieldRelation> paramsFieldRelationList = paramsFieldRelationMapper.
                                        selectParamsFieldRelations(paramsFieldRelation);
                                virtualUsageParamSource.setInterfaceId(paramsFieldRelationList.get(0).getInterfaceId());
                            }
                            List<VirtualUsageParamSource> virtualUsageParamSourceList = this.virtualUsageParamSourceMapper.selectVirtualUsageParamSourceList2(virtualUsageParamSource);
                            if (CollectionUtil.isEmpty(virtualUsageParamSourceList)) {
                                this.virtualUsageParamSourceMapper.insertVirtualUsageParamSource(virtualUsageParamSource);
                            }
                        }
                    }
                }
            }
        });
        return success();
    }

    /**
     * 出参字段来源选择页面
     * @author chenxiaoyu
     * @date 2022/4/14 下午11:53
     * @param interfaceId
     * @param interfaceFieldId 接口字段id
     * @param interfaceFieldType 接口字段类型 1 字段 2 数据集 3 数据集字段
     * @param mmap 页面
     * @return java.lang.String
     */
    @GetMapping("/outParamFieldSourceChoose")
    public String outParamFieldSourceChoose(Long interfaceId,
                                            Long interfaceFieldId,
                                     String interfaceFieldType,
                                     ModelMap mmap) {
        mmap.put("interfaceId", interfaceId);
        mmap.put("interfaceFieldId", interfaceFieldId);
        mmap.put("interfaceFieldType", interfaceFieldType);
        VirtualUsage virtualUsage = new VirtualUsage();
        virtualUsage.setRelationInterfaceId(interfaceId);
        List<VirtualUsage> virtualUsageList = this.virtualUsageService.selectVirtualUsages(virtualUsage);
        VirtualUsageParamSource virtualUsageParamSource = new VirtualUsageParamSource();
        virtualUsageParamSource.setIsInParam("2");
        virtualUsageParamSource.setInterfaceId(interfaceId);
        virtualUsageParamSource.setObjectId(interfaceFieldId);
        if (interfaceFieldType.equals("3")) {
            virtualUsageParamSource.setType("2");
            mmap.put("type", "2");
        } else {
            virtualUsageParamSource.setType("1");
            mmap.put("type", "1");
        }
        InterfaceInfo interfaceInfo = this.interfaceInfoService.selectInterfaceInfoById(interfaceId);
        if ("Y".equals(interfaceInfo.getIsBranch())) {
            VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
            virtualUsageGroup.setInterfaceId(interfaceId);
            List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
            if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
                for (VirtualUsageGroup usageGroup : virtualUsageGroups) {
                    VirtualUsage usage = new VirtualUsage();
                    usage.setId(usageGroup.getId());
                    usage.setSlaveInterfaceName(usageGroup.getGroupName());
                    usage.setVirtualUsageType("5");
                    usage.setIsMaster(usageGroup.getIsMaster());
                    virtualUsageList.add(usage);
                }
            }
        }
        for (VirtualUsage usage : virtualUsageList) {
            if (usage.getVirtualUsageType() == null) {
                usage.setVirtualUsageType("3");
            }
            if ("Y".equals(usage.getIsMaster())) {
                usage.setSlaveInterfaceName(usage.getSlaveInterfaceName() + " （主）");
            }
        }
        List<VirtualUsageParamSource> virtualUsageParamSourceList = this.virtualUsageParamSourceMapper.selectVirtualUsageParamSourceList(virtualUsageParamSource);
        mmap.put("virtualUsageParamSourceList", virtualUsageParamSourceList);
        mmap.put("virtualUsageList", virtualUsageList);
        return prefix + "/outParamFieldSourceChoose";
    }

    /**
     * 保存出参字段来源
     * @author chenxiaoyu
     * @date 2022/4/15 上午12:36
     * @param virtualUsageParamSource 参数
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @PostMapping("/saveOutParamFieldSource")
    @ResponseBody
    public AjaxResult saveOutParamFieldSource(VirtualUsageParamSource virtualUsageParamSource) {
        this.virtualUsageParamSourceService.saveOutParamFieldSource(virtualUsageParamSource);
        return success();
    }
    /**
     * 重置出参字段来源
     * @author chenxiaoyu
     * @date 2022/4/15 上午12:36
     * @param virtualUsageParamSource 参数
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @PostMapping("/resetOutParamFieldSource")
    @ResponseBody
    public AjaxResult resetOutParamFieldSource(VirtualUsageParamSource virtualUsageParamSource) {
        virtualUsageParamSource.setFieldId(null);
        this.virtualUsageParamSourceService.saveOutParamFieldSource(virtualUsageParamSource);
        return success();
    }

    /**
     * 查询字段被哪些接口引用
     * @author chenxiaoyu
     * @date 2022/4/19 上午12:19
     * @param fieldId
     * @param type
     * @param modelMap
     * @return java.lang.String
     */
    @GetMapping("/relationInterface")
    public String relationInterface(Long fieldId, String type, ModelMap modelMap) {
        List<InterfaceInfo> interfaceInfoList = new ArrayList<>();
        modelMap.put("interfaceInfoList", interfaceInfoList);
        if ("1".equals(type)) {
            InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(fieldId);
            if (interfaceParamsFieldRelation != null) {
                if (interfaceParamsFieldRelation.getType().equals("1") || interfaceParamsFieldRelation.getType().equals("4")) {
                    // method dubbo
                    List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(Collections.singletonList(fieldId), "1");
                    if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                        // 虚拟用况
                        Set<Long> interfaceIds = interfaceParamsFieldRelationList.stream().map(o -> o.getInterfaceId()).collect(Collectors.toSet());
                        VirtualUsage virtualUsage = new VirtualUsage();
                        virtualUsage.setIds(interfaceIds);
                        List<VirtualUsage> virtualUsages = this.virtualUsageService.selectVirtualUsages(virtualUsage);
                        if (CollectionUtil.isNotEmpty(virtualUsages)) {
                            for (VirtualUsage usage : virtualUsages) {
                                InterfaceInfo interfaceInfo = new InterfaceInfo();
                                interfaceInfo.setId(usage.getId());
                                interfaceInfo.setInterfaceName(usage.getSlaveInterfaceName());
                                interfaceInfo.setFbType("4");
                                interfaceInfo.setRelationInterfaceName(usage.getMasterInterfaceName());
                                interfaceInfoList.add(interfaceInfo);
                            }
                        }
                    }
                } else if (interfaceParamsFieldRelation.getType().equals("5")) {
                    // method dubbo
                    List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(Collections.singletonList(fieldId), "1");
                    if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                        // 虚拟用况组
                        List<Long> interfaceIds = interfaceParamsFieldRelationList.stream().map(o -> o.getInterfaceId()).collect(Collectors.toList());
                        VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
                        virtualUsageGroup.setIds(interfaceIds);
                        List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
                        if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
                            for (VirtualUsageGroup usageGroup : virtualUsageGroups) {
                                InterfaceInfo interfaceInfo = new InterfaceInfo();
                                interfaceInfo.setId(usageGroup.getId());
                                interfaceInfo.setFbType("5");
                                interfaceInfo.setInterfaceName(usageGroup.getGroupName());
                                interfaceInfo.setRelationInterfaceName(usageGroup.getInterfaceName());
                                interfaceInfoList.add(interfaceInfo);
                            }
                        }
                    }
                } else if (interfaceParamsFieldRelation.getType().equals("3")) {
                    List<Long> ids = new ArrayList<>();
                    // 虚拟用况
                    if (interfaceParamsFieldRelation.getObjectType().equals("1")) {
                        // 2.查询paramsFieldRelation表
                        List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(Collections.singletonList(fieldId), "1");
                        if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
                            ids.addAll(paramsFieldRelationList.stream().map(o -> o.getInterfaceDataListId()).collect(Collectors.toList()));
                        }
                        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(Collections.singletonList(fieldId), "1");
                        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                            for (InterfaceParamsFieldRelation paramsFieldRelation : interfaceParamsFieldRelationList) {
                                ids.add(paramsFieldRelation.getId());
                            }
                        }
                    } else {
                        ParamsFieldRelation paramsFieldRelation = new ParamsFieldRelation();
                        paramsFieldRelation.setInterfaceDataListId(fieldId);
                        List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationService.selectParamsFieldRelationList(paramsFieldRelation);
                        if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
                            List<Long> collect = paramsFieldRelationList.stream().map(ParamsFieldRelation::getId).collect(Collectors.toList());
                            // 1.查询interfaceParamsFieldRelation表
                            List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(collect, "2");
                            if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                                // return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                                interfaceParamsFieldRelationList.forEach( o-> {
                                    ids.add(o.getId());
                                });
                            }
                            // 2.查询paramsFieldRelation表
                            List<ParamsFieldRelation> paramsFieldRelationList2 = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(collect, "2");
                            if (CollectionUtil.isNotEmpty(paramsFieldRelationList2)) {
                                // return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                                for (ParamsFieldRelation fieldRelation : paramsFieldRelationList2) {
                                    ids.add(fieldRelation.getInterfaceDataListId());
                                }
                            }

                        }
                    }
                    InterfaceParamsFieldRelation interfaceParamsFieldRelation1 = new InterfaceParamsFieldRelation();
                    interfaceParamsFieldRelation1.setIds(ids);
                    List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation1);
                    if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                        List<Long> interfaceIds = new ArrayList<>();
                        List<Long> groupIds = new ArrayList<>();
                        interfaceParamsFieldRelationList.forEach(o -> {
                            if (o.getType().equals("5")) {
                                groupIds.add(o.getInterfaceId());
                            } else {
                                interfaceIds.add(o.getInterfaceId());
                            }
                        });
                        if (interfaceIds.size() > 0) {
                            InterfaceInfo interfaceInfo = new InterfaceInfo();
                            interfaceInfo.setIds(interfaceIds);
                            interfaceInfoList.addAll(this.interfaceInfoService.selectInterfaceInfoList(interfaceInfo));
                        }
                        if (groupIds.size() > 0) {
                            VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
                            virtualUsageGroup.setIds(groupIds);
                            List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
                            if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
                                for (VirtualUsageGroup usageGroup : virtualUsageGroups) {
                                    InterfaceInfo interfaceInfo = new InterfaceInfo();
                                    interfaceInfo.setId(usageGroup.getId());
                                    interfaceInfo.setFbType("5");
                                    interfaceInfo.setInterfaceName(usageGroup.getGroupName());
                                    interfaceInfo.setRelationInterfaceName(usageGroup.getInterfaceName());
                                    interfaceInfoList.add(interfaceInfo);
                                }
                            }
                        }
                    }
                }
            }
        } else {
            ParamsFieldRelation paramsFieldRelation = this.paramsFieldRelationService.selectParamsFieldRelationById(fieldId);
            if (paramsFieldRelation != null) {
                InterfaceParamsFieldRelation interfaceParamsFieldRelation = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationById(paramsFieldRelation.getInterfaceDataListId());
                if (interfaceParamsFieldRelation != null) {
                    if (interfaceParamsFieldRelation.getType().equals("1") || interfaceParamsFieldRelation.getType().equals("4")) {
                        // method dubbo
                        List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(Collections.singletonList(fieldId), "2");
                        if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
                            //return AjaxResult.warn("该字段与虚拟用况有关联，请解除关联");
                            List<Long> ids = new ArrayList<>();
                            for (ParamsFieldRelation fieldRelation : paramsFieldRelationList) {
                                ids.add(fieldRelation.getInterfaceDataListId());
                            }

                            InterfaceParamsFieldRelation interfaceParamsFieldRelation1 = new InterfaceParamsFieldRelation();
                            interfaceParamsFieldRelation1.setIds(ids);
                            List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList2 = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation1);
                            if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList2)) {
                                Set<Long> interfaceIds = interfaceParamsFieldRelationList2.stream().map(o -> o.getInterfaceId()).collect(Collectors.toSet());
                                VirtualUsage virtualUsage = new VirtualUsage();
                                virtualUsage.setIds(interfaceIds);
                                List<VirtualUsage> virtualUsages = this.virtualUsageService.selectVirtualUsages(virtualUsage);
                                if (CollectionUtil.isNotEmpty(virtualUsages)) {
                                    for (VirtualUsage usage : virtualUsages) {
                                        InterfaceInfo interfaceInfo = new InterfaceInfo();
                                        interfaceInfo.setId(usage.getId());
                                        interfaceInfo.setInterfaceName(usage.getSlaveInterfaceName());
                                        interfaceInfo.setRelationInterfaceName(usage.getMasterInterfaceName());
                                        interfaceInfo.setFbType("4");
                                        interfaceInfoList.add(interfaceInfo);
                                    }
                                }
                            }
                        }
                    } else if (interfaceParamsFieldRelation.getType().equals("5")) {
                        List<ParamsFieldRelation> paramsFieldRelationList = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(Collections.singletonList(fieldId), "2");
                        if (CollectionUtil.isNotEmpty(paramsFieldRelationList)) {
                            //return AjaxResult.warn("该字段与虚拟用况有关联，请解除关联");
                            List<Long> ids = new ArrayList<>();
                            for (ParamsFieldRelation fieldRelation : paramsFieldRelationList) {
                                ids.add(fieldRelation.getInterfaceDataListId());
                            }

                            InterfaceParamsFieldRelation interfaceParamsFieldRelation1 = new InterfaceParamsFieldRelation();
                            interfaceParamsFieldRelation1.setIds(ids);
                            List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList2 = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation1);
                            if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList2)) {
                                List<Long> interfaceIds = interfaceParamsFieldRelationList2.stream().map(o -> o.getInterfaceId()).collect(Collectors.toList());
                                VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
                                virtualUsageGroup.setIds(interfaceIds);
                                List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
                                if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
                                    for (VirtualUsageGroup usageGroup : virtualUsageGroups) {
                                        InterfaceInfo interfaceInfo = new InterfaceInfo();
                                        interfaceInfo.setId(usageGroup.getId());
                                        interfaceInfo.setFbType("5");
                                        interfaceInfo.setInterfaceName(usageGroup.getGroupName());
                                        interfaceInfo.setRelationInterfaceName(usageGroup.getInterfaceName());
                                        interfaceInfoList.add(interfaceInfo);
                                    }
                                }
                            }
                        }
                    }else {
                        List<Long> ids = new ArrayList<>();
                        // 虚拟用况
                        // 1.查询interfaceParamsFieldRelation表
                        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationByDataRelationId(Collections.singletonList(fieldId), "2");
                        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList)) {
                            //return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                            for (InterfaceParamsFieldRelation fieldRelation : interfaceParamsFieldRelationList) {
                                ids.add(fieldRelation.getId());
                            }
                        }
                        // 2.查询paramsFieldRelation表
                        List<ParamsFieldRelation> paramsFieldRelationList2 = this.paramsFieldRelationService.selectParamsFieldRelationListByDataRelationId(Collections.singletonList(fieldId), "2");
                        if (CollectionUtil.isNotEmpty(paramsFieldRelationList2)) {
                            //return AjaxResult.warn("该字段与bff或者dubbo有关联，请解除关联");
                            for (ParamsFieldRelation fieldRelation : paramsFieldRelationList2) {
                                ids.add(fieldRelation.getInterfaceDataListId());
                            }
                        }

                        InterfaceParamsFieldRelation interfaceParamsFieldRelation1 = new InterfaceParamsFieldRelation();
                        interfaceParamsFieldRelation1.setIds(ids);
                        List<InterfaceParamsFieldRelation> interfaceParamsFieldRelationList2 = this.interfaceParamsFieldRelationService.selectInterfaceParamsFieldRelationList(interfaceParamsFieldRelation1);
                        if (CollectionUtil.isNotEmpty(interfaceParamsFieldRelationList2)) {
                            List<Long> interfaceIds = new ArrayList<>();
                            List<Long> groupIds = new ArrayList<>();
                            interfaceParamsFieldRelationList2.forEach(o -> {
                                if (o.getType().equals("5")) {
                                    groupIds.add(o.getInterfaceId());
                                } else {
                                    interfaceIds.add(o.getInterfaceId());
                                }
                            });
                            if (interfaceIds.size() > 0) {
                                InterfaceInfo interfaceInfo = new InterfaceInfo();
                                interfaceInfo.setIds(interfaceIds);
                                interfaceInfoList.addAll(this.interfaceInfoService.selectInterfaceInfoList(interfaceInfo));
                            }
                            if (groupIds.size() > 0) {
                                VirtualUsageGroup virtualUsageGroup = new VirtualUsageGroup();
                                virtualUsageGroup.setIds(groupIds);
                                List<VirtualUsageGroup> virtualUsageGroups = this.virtualUsageGroupService.selectVirtualUsageGroupList(virtualUsageGroup);
                                if (CollectionUtil.isNotEmpty(virtualUsageGroups)) {
                                    for (VirtualUsageGroup usageGroup : virtualUsageGroups) {
                                        InterfaceInfo interfaceInfo = new InterfaceInfo();
                                        interfaceInfo.setId(usageGroup.getId());
                                        interfaceInfo.setFbType("5");
                                        interfaceInfo.setInterfaceName(usageGroup.getGroupName());
                                        interfaceInfo.setRelationInterfaceName(usageGroup.getInterfaceName());
                                        interfaceInfoList.add(interfaceInfo);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return prefix + "/relationInterface";
    }
}
